Skip to content

Commit e70284b

Browse files
Add midi editor add note
1 parent 4f95df0 commit e70284b

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

src/ui/component/editor/MIDIContentViewer.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#include "MIDIContentViewer.h"
22
#include "../../misc/Tools.h"
3+
#include "../../misc/CoreActions.h"
34
#include "../../lookAndFeel/LookAndFeelFactory.h"
45
#include "../../Utils.h"
56
#include "../../../audioCore/AC_API.h"
67

8+
#define NOTE_VELOCITY_INIT 127
9+
710
class MIDIChannelListener final : public juce::ChangeListener {
811
public:
912
MIDIChannelListener() = delete;
@@ -531,7 +534,8 @@ void MIDIContentViewer::midiChannelChanged() {
531534
void MIDIContentViewer::insertNote(
532535
double startTime, double length,
533536
uint8_t pitch, uint8_t channel) {
534-
/** TODO */
537+
CoreActions::midiAddNote(this->ref, this->currentMIDITrack,
538+
startTime, startTime + length, channel, pitch, NOTE_VELOCITY_INIT);
535539
}
536540

537541
void MIDIContentViewer::updateKeyImageTemp() {

src/ui/misc/CoreActions.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,63 @@ void CoreActions::removeSeqBlock(int track, int index) {
502502
ActionDispatcher::getInstance()->dispatch(std::move(action));
503503
}
504504

505+
void CoreActions::midiAddNote(
506+
uint64_t ref, int track, double startTime, double endTime, uint8_t channel,
507+
uint8_t pitch, uint8_t vel, const juce::String& lyrics) {
508+
auto action = std::unique_ptr<ActionUndoableBase>(
509+
new ActionMIDIAddNote{ ref, track, startTime, endTime,
510+
channel, pitch, vel, lyrics });
511+
ActionDispatcher::getInstance()->dispatch(std::move(action));
512+
}
513+
514+
void CoreActions::midiSetNoteTime(
515+
uint64_t ref, int track, int index,
516+
double startTime, double endTime) {
517+
auto action = std::unique_ptr<ActionUndoableBase>(
518+
new ActionMIDISetNoteTime{
519+
ref, track, index, startTime, endTime });
520+
ActionDispatcher::getInstance()->dispatch(std::move(action));
521+
}
522+
523+
void CoreActions::midiSetNoteChannel(
524+
uint64_t ref, int track, int index,
525+
uint8_t channel) {
526+
auto action = std::unique_ptr<ActionUndoableBase>(
527+
new ActionMIDISetNoteChannel{ ref, track, index, channel });
528+
ActionDispatcher::getInstance()->dispatch(std::move(action));
529+
}
530+
531+
void CoreActions::midiSetNotePitch(
532+
uint64_t ref, int track, int index,
533+
uint8_t pitch) {
534+
auto action = std::unique_ptr<ActionUndoableBase>(
535+
new ActionMIDISetNotePitch{ ref, track, index, pitch });
536+
ActionDispatcher::getInstance()->dispatch(std::move(action));
537+
}
538+
539+
void CoreActions::midiSetNoteVelocity(
540+
uint64_t ref, int track, int index,
541+
uint8_t velocity) {
542+
auto action = std::unique_ptr<ActionUndoableBase>(
543+
new ActionMIDISetNoteVelocity{ ref, track, index, velocity });
544+
ActionDispatcher::getInstance()->dispatch(std::move(action));
545+
}
546+
547+
void CoreActions::midiSetNoteLyrics(
548+
uint64_t ref, int track, int index,
549+
const juce::String& lyrics) {
550+
auto action = std::unique_ptr<ActionUndoableBase>(
551+
new ActionMIDISetNoteLyrics{ ref, track, index, lyrics });
552+
ActionDispatcher::getInstance()->dispatch(std::move(action));
553+
}
554+
555+
void CoreActions::midiRemoveNote(
556+
uint64_t ref, int track, int index) {
557+
auto action = std::unique_ptr<ActionUndoableBase>(
558+
new ActionMIDIRemoveNote{ ref, track, index });
559+
ActionDispatcher::getInstance()->dispatch(std::move(action));
560+
}
561+
505562
void CoreActions::loadProjectGUI(const juce::String& filePath) {
506563
if (!CoreActions::askForSaveGUI()) { return; }
507564

src/ui/misc/CoreActions.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,27 @@ class CoreActions final {
123123
static void setSeqBlock(int track, int index, double startTime, double endTime, double offset);
124124
static void removeSeqBlock(int track, int index);
125125

126+
static void midiAddNote(
127+
uint64_t ref, int track, double startTime, double endTime, uint8_t channel,
128+
uint8_t pitch, uint8_t vel, const juce::String& lyrics = "");
129+
static void midiSetNoteTime(
130+
uint64_t ref, int track, int index,
131+
double startTime, double endTime);
132+
static void midiSetNoteChannel(
133+
uint64_t ref, int track, int index,
134+
uint8_t channel);
135+
static void midiSetNotePitch(
136+
uint64_t ref, int track, int index,
137+
uint8_t pitch);
138+
static void midiSetNoteVelocity(
139+
uint64_t ref, int track, int index,
140+
uint8_t velocity);
141+
static void midiSetNoteLyrics(
142+
uint64_t ref, int track, int index,
143+
const juce::String& lyrics);
144+
static void midiRemoveNote(
145+
uint64_t ref, int track, int index);
146+
126147
using CreateAudioSourceCancelCallback = std::function<void(int)>;
127148
using CreateMIDISourceCancelCallback = CreateAudioSourceCancelCallback;
128149

0 commit comments

Comments
 (0)