Skip to content

Commit d2253ce

Browse files
Add MIDI note remove action
1 parent 0143895 commit d2253ce

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

src/audioCore/action/ActionMIDI.cpp

+58
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,61 @@ void ActionMIDISetNoteLyrics::getRecoveryData(juce::MemoryOutputStream& stream)
248248
stream.writeString(this->lyrics);
249249
stream.writeString(this->oldLyrics);
250250
}
251+
252+
ActionMIDIRemoveNote::ActionMIDIRemoveNote(
253+
uint64_t ref, int track, int index)
254+
: ref(ref), track(track), index(index) {}
255+
256+
bool ActionMIDIRemoveNote::doAction() {
257+
/** Get Note Data */
258+
auto note = SourceManager::getInstance()->getMIDINote(
259+
this->ref, this->track, this->index);
260+
if (note.eventOffIndex < 0) { return false; }
261+
262+
this->startTime = note.timeSec;
263+
this->endTime = note.endSec;
264+
this->channel = note.channel;
265+
this->pitch = note.pitch;
266+
this->vel = note.vel;
267+
this->lyrics = note.lyrics;
268+
269+
this->oldEndIndex = note.eventOffIndex;
270+
271+
/** Remove Note */
272+
return SourceManager::getInstance()->removeNote(
273+
this->ref, this->track, this->index);
274+
}
275+
276+
bool ActionMIDIRemoveNote::undoAction() {
277+
/** Restore Note */
278+
int index = SourceManager::getInstance()->addNote(
279+
this->ref, this->track, this->startTime, this->endTime,
280+
this->channel, this->pitch, this->vel, this->lyrics,
281+
this->index, this->oldEndIndex);
282+
return (index == this->index);
283+
}
284+
285+
const juce::String ActionMIDIRemoveNote::getStatusStr() const {
286+
return "Source: " + juce::String{ this->ref } + "\n" +
287+
"Track: " + juce::String{ this->track } + "\n" +
288+
"Index: " + juce::String{ this->index } + "\n" +
289+
"Time: " + juce::String{ this->startTime, 2 } + " - " + juce::String{ this->endTime, 2 } + "\n" +
290+
"Channel: " + juce::String{ this->channel } + "\n" +
291+
"Pitch: " + juce::String{ this->pitch } + "\n" +
292+
"Velocity: " + juce::String{ this->vel } + "\n" +
293+
"Lyrics: " + this->lyrics + "\n";
294+
}
295+
296+
void ActionMIDIRemoveNote::getRecoveryData(juce::MemoryOutputStream& stream) {
297+
stream.writeInt64((int64_t)this->ref);
298+
stream.writeInt(this->track);
299+
stream.writeInt(this->index);
300+
stream.writeDouble(this->startTime);
301+
stream.writeDouble(this->endTime);
302+
stream.writeByte((char)this->channel);
303+
stream.writeByte((char)this->pitch);
304+
stream.writeByte((char)this->vel);
305+
stream.writeString(this->lyrics);
306+
307+
stream.writeInt(this->oldEndIndex);
308+
}

src/audioCore/action/ActionMIDI.h

+31
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,34 @@ class ActionMIDISetNoteLyrics final : public ActionUndoableBase {
166166

167167
JUCE_LEAK_DETECTOR(ActionMIDISetNoteLyrics)
168168
};
169+
170+
class ActionMIDIRemoveNote final : public ActionUndoableBase {
171+
public:
172+
ActionMIDIRemoveNote() = delete;
173+
ActionMIDIRemoveNote(
174+
uint64_t ref, int track, int index);
175+
176+
bool doAction() override;
177+
bool undoAction() override;
178+
const juce::String getName() const override {
179+
return "MIDI Remove Note";
180+
};
181+
ActionType getActionType() const override { return ActionType::ActionMIDIRemoveNote; };
182+
const juce::String getStatusStr() const override;
183+
void getRecoveryData(juce::MemoryOutputStream& stream) override;
184+
185+
private:
186+
const uint64_t ref;
187+
const int track;
188+
const int index;
189+
190+
double startTime = 0, endTime = 0;
191+
uint8_t channel = 0;
192+
uint8_t pitch = 0;
193+
uint8_t vel = 0;
194+
juce::String lyrics;
195+
196+
int oldEndIndex = -1;
197+
198+
JUCE_LEAK_DETECTOR(ActionMIDIAddNote)
199+
};

0 commit comments

Comments
 (0)