LMMS
Loading...
Searching...
No Matches
StepRecorder.h
Go to the documentation of this file.
1/*
2 * This file is part of LMMS - https://lmms.io
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public
15 * License along with this program (see COPYING); if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA.
18 *
19 */
20
21#ifndef LMMS_STEP_RECORDER_H
22#define LMMS_STEP_RECORDER_H
23
24#include <QElapsedTimer>
25#include <QTimer>
26#include <QObject>
27
28#include "Note.h"
29
30class QKeyEvent;
31class QMouseEvent;
32
33namespace lmms
34{
35
36class MidiClip;
37
38namespace gui
39{
40class PianoRoll;
42} // namespace gui
43
44class StepRecorder : public QObject
45{
46 Q_OBJECT
47
48 public:
49 StepRecorder(gui::PianoRoll& pianoRoll, gui::StepRecorderWidget& stepRecorderWidget);
50
51 void initialize();
52 void start(const TimePos& currentPosition,const TimePos& stepLength);
53 void stop();
54 void notePressed(const Note & n);
55 void noteReleased(const Note & n);
56 bool keyPressEvent(QKeyEvent* ke);
57 bool mousePressEvent(QMouseEvent* ke);
58 void setCurrentMidiClip(MidiClip* newMidiClip);
59 void setStepsLength(const TimePos& newLength);
60
61 std::vector<Note*> getCurStepNotes();
62
63 bool isRecording() const
64 {
65 return m_isRecording;
66 }
67
68 private slots:
70
71 private:
72 void stepForwards();
73 void stepBackwards();
74
75 void applyStep();
76 void dismissStep();
77 void prepareNewStep();
78
80
81 void updateCurStepNotes();
82 void updateWidget();
83
85
88
89 bool m_isRecording = false;
92
94 TimePos m_curStepLength; // current step length refers to the step currently recorded. it may defer from m_stepsLength
95 // since the user can make current step larger
96
98
100
102 {
103 public:
104 StepNote(const Note & note) : m_note(note), m_pressed(true) {};
105
107 {
108 m_pressed = true;
109 }
110
112 {
113 m_pressed = false;
114 releasedTimer.start();
115 }
116
118 {
119 return releasedTimer.elapsed();
120 }
121
122 bool isPressed() const
123 {
124 return m_pressed;
125 }
126
127 bool isReleased() const
128 {
129 return !m_pressed;
130 }
131
133
134 private:
136 QElapsedTimer releasedTimer;
137 } ;
138
139 std::vector<StepNote*> m_curStepNotes; // contains the current recorded step notes (i.e. while user still press the notes; before they are applied to the clip)
140
141 StepNote* findCurStepNote(const int key);
142
143 bool m_isStepInProgress = false;
144};
145
146
147} // namespace lmms
148
149#endif // LMMS_STEP_RECORDER_H
Definition MidiClip.h:46
Definition Note.h:101
Definition StepRecorder.h:102
StepNote(const Note &note)
Definition StepRecorder.h:104
QElapsedTimer releasedTimer
Definition StepRecorder.h:136
void setPressed()
Definition StepRecorder.h:106
void setReleased()
Definition StepRecorder.h:111
Note m_note
Definition StepRecorder.h:132
bool isReleased() const
Definition StepRecorder.h:127
bool isPressed() const
Definition StepRecorder.h:122
int timeSinceReleased()
Definition StepRecorder.h:117
bool m_pressed
Definition StepRecorder.h:135
StepNote * findCurStepNote(const int key)
Definition StepRecorder.cpp:368
StepRecorder(gui::PianoRoll &pianoRoll, gui::StepRecorderWidget &stepRecorderWidget)
Definition StepRecorder.cpp:39
bool m_isRecording
Definition StepRecorder.h:89
TimePos m_curStepStartPos
Definition StepRecorder.h:90
bool mousePressEvent(QMouseEvent *ke)
void applyStep()
Definition StepRecorder.cpp:233
std::vector< StepNote * > m_curStepNotes
Definition StepRecorder.h:139
gui::PianoRoll & m_pianoRoll
Definition StepRecorder.h:86
QTimer m_updateReleasedTimer
Definition StepRecorder.h:97
void prepareNewStep()
Definition StepRecorder.cpp:260
void removeNotesReleasedForTooLong()
Definition StepRecorder.cpp:286
void updateWidget()
Definition StepRecorder.cpp:348
void updateCurStepNotes()
Definition StepRecorder.cpp:339
void stepForwards()
Definition StepRecorder.cpp:193
TimePos getCurStepEndPos()
Definition StepRecorder.cpp:334
TimePos m_stepsLength
Definition StepRecorder.h:93
void notePressed(const Note &n)
Definition StepRecorder.cpp:80
bool m_isStepInProgress
Definition StepRecorder.h:143
void initialize()
Definition StepRecorder.cpp:47
void dismissStep()
Definition StepRecorder.cpp:250
void setStepsLength(const TimePos &newLength)
Definition StepRecorder.cpp:163
bool isRecording() const
Definition StepRecorder.h:63
TimePos m_curStepLength
Definition StepRecorder.h:94
MidiClip * m_midiClip
Definition StepRecorder.h:99
void stop()
Definition StepRecorder.cpp:74
std::vector< Note * > getCurStepNotes()
Definition StepRecorder.cpp:178
bool keyPressEvent(QKeyEvent *ke)
Definition StepRecorder.cpp:133
bool allCurStepNotesReleased()
Definition StepRecorder.cpp:355
TimePos m_curStepEndPos
Definition StepRecorder.h:91
gui::StepRecorderWidget & m_stepRecorderWidget
Definition StepRecorder.h:87
void setCurrentMidiClip(MidiClip *newMidiClip)
Definition StepRecorder.cpp:276
void noteReleased(const Note &n)
Definition StepRecorder.cpp:103
void stepBackwards()
Definition StepRecorder.cpp:209
Definition TimePos.h:68
Definition PianoRoll.h:65
Definition StepRecorderWidget.h:35
virtual ASIOError start()=0
Definition AudioPortAudio.cpp:223
Definition AudioAlsa.cpp:35
#define true
Definition ordinals.h:82
int n
Definition crypt.c:458
ZCONST char * key
Definition crypt.c:587