Skip to content

Commit d4df151

Browse files
Add MIDI note editing actions
1 parent 4ca786b commit d4df151

File tree

2 files changed

+256
-0
lines changed

2 files changed

+256
-0
lines changed

src/audioCore/action/ActionMIDI.cpp

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,155 @@ void ActionMIDISetNoteTime::getRecoveryData(juce::MemoryOutputStream& stream) {
9696
stream.writeDouble(this->oldStartTime);
9797
stream.writeDouble(this->oldEndTime);
9898
}
99+
100+
ActionMIDISetNoteChannel::ActionMIDISetNoteChannel(
101+
uint64_t ref, int track, int index,
102+
uint8_t channel)
103+
: ref(ref), track(track), index(index), channel(channel) {}
104+
105+
bool ActionMIDISetNoteChannel::doAction() {
106+
/** Get Old Channel */
107+
auto note = SourceManager::getInstance()->getMIDINote(
108+
this->ref, this->track, this->index);
109+
if (note.eventOffIndex < 0) { return false; }
110+
this->oldChannel = note.channel;
111+
112+
/** Set Channel */
113+
return SourceManager::getInstance()->setNoteChannel(
114+
this->ref, this->track, this->index, this->channel);
115+
}
116+
117+
bool ActionMIDISetNoteChannel::undoAction() {
118+
return SourceManager::getInstance()->setNoteChannel(
119+
this->ref, this->track, this->index, this->oldChannel);
120+
}
121+
122+
const juce::String ActionMIDISetNoteChannel::getStatusStr() const {
123+
return "Source: " + juce::String{ this->ref } + "\n" +
124+
"Track: " + juce::String{ this->track } + "\n" +
125+
"Index: " + juce::String{ this->index } + "\n" +
126+
"Old Channel: " + juce::String{ this->oldChannel } + "\n" +
127+
"Channel: " + juce::String{ this->channel } + "\n";
128+
}
129+
130+
void ActionMIDISetNoteChannel::getRecoveryData(juce::MemoryOutputStream& stream) {
131+
stream.writeInt64((int64_t)this->ref);
132+
stream.writeInt(this->track);
133+
stream.writeInt(this->index);
134+
stream.writeByte((char)this->channel);
135+
stream.writeByte((char)this->oldChannel);
136+
}
137+
138+
ActionMIDISetNotePitch::ActionMIDISetNotePitch(
139+
uint64_t ref, int track, int index,
140+
uint8_t pitch)
141+
: ref(ref), track(track), index(index), pitch(pitch) {}
142+
143+
bool ActionMIDISetNotePitch::doAction() {
144+
/** Get Old Pitch */
145+
auto note = SourceManager::getInstance()->getMIDINote(
146+
this->ref, this->track, this->index);
147+
if (note.eventOffIndex < 0) { return false; }
148+
this->oldPitch = note.pitch;
149+
150+
/** Set Pitch */
151+
return SourceManager::getInstance()->setNotePitch(
152+
this->ref, this->track, this->index, this->pitch);
153+
}
154+
155+
bool ActionMIDISetNotePitch::undoAction() {
156+
return SourceManager::getInstance()->setNotePitch(
157+
this->ref, this->track, this->index, this->oldPitch);
158+
}
159+
160+
const juce::String ActionMIDISetNotePitch::getStatusStr() const {
161+
return "Source: " + juce::String{ this->ref } + "\n" +
162+
"Track: " + juce::String{ this->track } + "\n" +
163+
"Index: " + juce::String{ this->index } + "\n" +
164+
"Old Pitch: " + juce::String{ this->oldPitch } + "\n" +
165+
"Pitch: " + juce::String{ this->pitch } + "\n";
166+
}
167+
168+
void ActionMIDISetNotePitch::getRecoveryData(juce::MemoryOutputStream& stream) {
169+
stream.writeInt64((int64_t)this->ref);
170+
stream.writeInt(this->track);
171+
stream.writeInt(this->index);
172+
stream.writeByte((char)this->pitch);
173+
stream.writeByte((char)this->oldPitch);
174+
}
175+
176+
ActionMIDISetNoteVelocity::ActionMIDISetNoteVelocity(
177+
uint64_t ref, int track, int index,
178+
uint8_t velocity)
179+
: ref(ref), track(track), index(index), velocity(velocity) {}
180+
181+
bool ActionMIDISetNoteVelocity::doAction() {
182+
/** Get Old Velocity */
183+
auto note = SourceManager::getInstance()->getMIDINote(
184+
this->ref, this->track, this->index);
185+
if (note.eventOffIndex < 0) { return false; }
186+
this->oldVelocity = note.vel;
187+
188+
/** Set Velocity */
189+
return SourceManager::getInstance()->setNoteVelocity(
190+
this->ref, this->track, this->index, this->velocity);
191+
}
192+
193+
bool ActionMIDISetNoteVelocity::undoAction() {
194+
return SourceManager::getInstance()->setNoteVelocity(
195+
this->ref, this->track, this->index, this->oldVelocity);
196+
}
197+
198+
const juce::String ActionMIDISetNoteVelocity::getStatusStr() const {
199+
return "Source: " + juce::String{ this->ref } + "\n" +
200+
"Track: " + juce::String{ this->track } + "\n" +
201+
"Index: " + juce::String{ this->index } + "\n" +
202+
"Old Velocity: " + juce::String{ this->oldVelocity } + "\n" +
203+
"Velocity: " + juce::String{ this->velocity } + "\n";
204+
}
205+
206+
void ActionMIDISetNoteVelocity::getRecoveryData(juce::MemoryOutputStream& stream) {
207+
stream.writeInt64((int64_t)this->ref);
208+
stream.writeInt(this->track);
209+
stream.writeInt(this->index);
210+
stream.writeByte((char)this->velocity);
211+
stream.writeByte((char)this->oldVelocity);
212+
}
213+
214+
ActionMIDISetNoteLyrics::ActionMIDISetNoteLyrics(
215+
uint64_t ref, int track, int index,
216+
const juce::String& lyrics)
217+
: ref(ref), track(track), index(index), lyrics(lyrics) {}
218+
219+
bool ActionMIDISetNoteLyrics::doAction() {
220+
/** Get Old Lyrics */
221+
auto note = SourceManager::getInstance()->getMIDINote(
222+
this->ref, this->track, this->index);
223+
if (note.eventOffIndex < 0) { return false; }
224+
this->oldLyrics = note.lyrics;
225+
226+
/** Set Lyrics */
227+
return SourceManager::getInstance()->setNoteLyrics(
228+
this->ref, this->track, this->index, this->lyrics);
229+
}
230+
231+
bool ActionMIDISetNoteLyrics::undoAction() {
232+
return SourceManager::getInstance()->setNoteLyrics(
233+
this->ref, this->track, this->index, this->oldLyrics);
234+
}
235+
236+
const juce::String ActionMIDISetNoteLyrics::getStatusStr() const {
237+
return "Source: " + juce::String{ this->ref } + "\n" +
238+
"Track: " + juce::String{ this->track } + "\n" +
239+
"Index: " + juce::String{ this->index } + "\n" +
240+
"Old Lyrics: " + this->oldLyrics + "\n" +
241+
"Lyrics: " + this->lyrics + "\n";
242+
}
243+
244+
void ActionMIDISetNoteLyrics::getRecoveryData(juce::MemoryOutputStream& stream) {
245+
stream.writeInt64((int64_t)this->ref);
246+
stream.writeInt(this->track);
247+
stream.writeInt(this->index);
248+
stream.writeString(this->lyrics);
249+
stream.writeString(this->oldLyrics);
250+
}

src/audioCore/action/ActionMIDI.h

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,107 @@ class ActionMIDISetNoteTime final : public ActionUndoableBase {
6262

6363
JUCE_LEAK_DETECTOR(ActionMIDISetNoteTime)
6464
};
65+
66+
class ActionMIDISetNoteChannel final : public ActionUndoableBase {
67+
public:
68+
ActionMIDISetNoteChannel() = delete;
69+
ActionMIDISetNoteChannel(
70+
uint64_t ref, int track, int index,
71+
uint8_t channel);
72+
73+
bool doAction() override;
74+
bool undoAction() override;
75+
const juce::String getName() const override {
76+
return "MIDI Set Note Channel";
77+
};
78+
ActionType getActionType() const override { return ActionType::ActionMIDISetNoteChannel; };
79+
const juce::String getStatusStr() const override;
80+
void getRecoveryData(juce::MemoryOutputStream& stream) override;
81+
82+
private:
83+
const uint64_t ref;
84+
const int track, index;
85+
const uint8_t channel;
86+
87+
uint8_t oldChannel = 0;
88+
89+
JUCE_LEAK_DETECTOR(ActionMIDISetNoteChannel)
90+
};
91+
92+
class ActionMIDISetNotePitch final : public ActionUndoableBase {
93+
public:
94+
ActionMIDISetNotePitch() = delete;
95+
ActionMIDISetNotePitch(
96+
uint64_t ref, int track, int index,
97+
uint8_t pitch);
98+
99+
bool doAction() override;
100+
bool undoAction() override;
101+
const juce::String getName() const override {
102+
return "MIDI Set Note Pitch";
103+
};
104+
ActionType getActionType() const override { return ActionType::ActionMIDISetNotePitch; };
105+
const juce::String getStatusStr() const override;
106+
void getRecoveryData(juce::MemoryOutputStream& stream) override;
107+
108+
private:
109+
const uint64_t ref;
110+
const int track, index;
111+
const uint8_t pitch;
112+
113+
uint8_t oldPitch = 0;
114+
115+
JUCE_LEAK_DETECTOR(ActionMIDISetNotePitch)
116+
};
117+
118+
class ActionMIDISetNoteVelocity final : public ActionUndoableBase {
119+
public:
120+
ActionMIDISetNoteVelocity() = delete;
121+
ActionMIDISetNoteVelocity(
122+
uint64_t ref, int track, int index,
123+
uint8_t velocity);
124+
125+
bool doAction() override;
126+
bool undoAction() override;
127+
const juce::String getName() const override {
128+
return "MIDI Set Note Velocity";
129+
};
130+
ActionType getActionType() const override { return ActionType::ActionMIDISetNoteVelocity; };
131+
const juce::String getStatusStr() const override;
132+
void getRecoveryData(juce::MemoryOutputStream& stream) override;
133+
134+
private:
135+
const uint64_t ref;
136+
const int track, index;
137+
const uint8_t velocity;
138+
139+
uint8_t oldVelocity = 0;
140+
141+
JUCE_LEAK_DETECTOR(ActionMIDISetNoteVelocity)
142+
};
143+
144+
class ActionMIDISetNoteLyrics final : public ActionUndoableBase {
145+
public:
146+
ActionMIDISetNoteLyrics() = delete;
147+
ActionMIDISetNoteLyrics(
148+
uint64_t ref, int track, int index,
149+
const juce::String& lyrics);
150+
151+
bool doAction() override;
152+
bool undoAction() override;
153+
const juce::String getName() const override {
154+
return "MIDI Set Note Lyrics";
155+
};
156+
ActionType getActionType() const override { return ActionType::ActionMIDISetNoteLyrics; };
157+
const juce::String getStatusStr() const override;
158+
void getRecoveryData(juce::MemoryOutputStream& stream) override;
159+
160+
private:
161+
const uint64_t ref;
162+
const int track, index;
163+
const juce::String lyrics;
164+
165+
juce::String oldLyrics;
166+
167+
JUCE_LEAK_DETECTOR(ActionMIDISetNoteLyrics)
168+
};

0 commit comments

Comments
 (0)