Skip to content

Commit

Permalink
Add MIDI temp events
Browse files Browse the repository at this point in the history
  • Loading branch information
FangCunWuChang committed Sep 9, 2024
1 parent 219af2a commit a11e9c2
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 4 deletions.
124 changes: 120 additions & 4 deletions src/audioCore/source/SourceMIDITemp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,43 @@ void SourceMIDITemp::addTrack(const juce::MidiMessageSequence& track) {
}

void SourceMIDITemp::update() {
/** Clear Lists */
this->noteList.clear();
this->sustainPedalList.clear();
this->sostenutoPedalList.clear();
this->softPedalList.clear();
this->pitchWheelList.clear();
this->afterTouchList.clear();
this->channelPressureList.clear();
this->controllerList.clear();
this->miscList.clear();

/** For Each Track */
for (int i = 0; i < this->sourceData.getNumTracks(); i++) {
auto track = this->sourceData.getTrack(i);
double endTime = track->getEndTime();

/** For Each Event */
/** Track Event Temp */
juce::Array<Note> noteTrack;
juce::String lyricsTemp;
double lyricsTimeTemp = 0;

juce::Array<Pedal> sustain, sostenuto, soft;
juce::Array<IntParam> pitchWheel, afterTouch, channelPressure;
std::unordered_map<uint8_t, juce::Array<Controller>> controllers;
juce::Array<Misc> miscs;

/** For Each Event */
for (int i = 0; i < track->getNumEvents(); i++) {
auto event = track->getEventPointer(i);

/** Get Notes */
if (event->message.isNoteOn(true)) {
Note note;
Note note{};
note.channel = (uint8_t)event->message.getChannel();
note.startSec = event->message.getTimeStamp();
note.endSec = event->noteOffObject ? event->noteOffObject->message.getTimeStamp() : endTime;
note.pitch = event->message.getNoteNumber();
note.pitch = (uint8_t)event->message.getNoteNumber();
note.vel = event->message.getVelocity();
if (note.startSec == lyricsTimeTemp) {
note.lyrics = lyricsTemp;
Expand All @@ -46,10 +65,107 @@ void SourceMIDITemp::update() {
lyricsTimeTemp = event->message.getTimeStamp();
continue;
}
/** TODO */
/** Sustain Pedal */
if (event->message.isSustainPedalOn() || event->message.isSustainPedalOff()) {
Pedal pedal{};
pedal.channel = (uint8_t)event->message.getChannel();
pedal.timeSec = event->message.getTimeStamp();
pedal.value = event->message.isSustainPedalOn();
pedal.event = i;

sustain.add(pedal);
continue;
}
/** Sostenuto Pedal */
if (event->message.isSostenutoPedalOn() || event->message.isSostenutoPedalOff()) {
Pedal pedal{};
pedal.channel = (uint8_t)event->message.getChannel();
pedal.timeSec = event->message.getTimeStamp();
pedal.value = event->message.isSostenutoPedalOn();
pedal.event = i;

sostenuto.add(pedal);
continue;
}
/** Soft Pedal */
if (event->message.isSoftPedalOn() || event->message.isSoftPedalOff()) {
Pedal pedal{};
pedal.channel = (uint8_t)event->message.getChannel();
pedal.timeSec = event->message.getTimeStamp();
pedal.value = event->message.isSoftPedalOn();
pedal.event = i;

soft.add(pedal);
continue;
}
/** Pitch Wheel */
if (event->message.isPitchWheel()) {
IntParam param{};
param.channel = (uint8_t)event->message.getChannel();
param.timeSec = event->message.getTimeStamp();
param.value = event->message.getPitchWheelValue();
param.event = i;

pitchWheel.add(param);
continue;
}
/** After Touch */
if (event->message.isAftertouch()) {
IntParam param{};
param.channel = (uint8_t)event->message.getChannel();
param.timeSec = event->message.getTimeStamp();
param.value = event->message.getAfterTouchValue();
param.event = i;

afterTouch.add(param);
continue;
}
/** Channel Pressure */
if (event->message.isChannelPressure()) {
IntParam param{};
param.channel = (uint8_t)event->message.getChannel();
param.timeSec = event->message.getTimeStamp();
param.value = event->message.getChannelPressureValue();
param.event = i;

channelPressure.add(param);
continue;
}
/** MIDI CC */
if (event->message.isController()) {
Controller controller{};
controller.channel = (uint8_t)event->message.getChannel();
controller.timeSec = event->message.getTimeStamp();
controller.number = (uint8_t)event->message.getControllerNumber();
controller.value = (uint8_t)event->message.getControllerValue();
controller.event = i;

controllers[controller.number].add(controller);
continue;
}
/** Other exclude Lyrics */
{
Misc misc{};
misc.channel = (uint8_t)event->message.getChannel();
misc.timeSec = event->message.getTimeStamp();
misc.message = event->message;
misc.event = i;

miscs.add(misc);
continue;
}
}

/** Add Track to List */
this->noteList.add(noteTrack);
this->sustainPedalList.add(sustain);
this->sostenutoPedalList.add(sostenuto);
this->softPedalList.add(soft);
this->pitchWheelList.add(pitchWheel);
this->afterTouchList.add(afterTouch);
this->channelPressureList.add(channelPressure);
this->controllerList.add(controllers);
this->miscList.add(miscs);
}
}

Expand Down
43 changes: 43 additions & 0 deletions src/audioCore/source/SourceMIDITemp.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SourceMIDITemp final {
juce::MidiFile sourceData;

struct Note {
uint8_t channel;
double startSec, endSec;
uint8_t pitch;
uint8_t vel;
Expand All @@ -24,4 +25,46 @@ class SourceMIDITemp final {
int noteOnEvent;
};
juce::Array<juce::Array<Note>> noteList;

struct Pedal {
uint8_t channel;
double timeSec;
bool value;

int event;
};
juce::Array<juce::Array<Pedal>> sustainPedalList;
juce::Array<juce::Array<Pedal>> sostenutoPedalList;
juce::Array<juce::Array<Pedal>> softPedalList;

struct IntParam {
uint8_t channel;
double timeSec;
int value;

int event;
};
juce::Array<juce::Array<IntParam>> pitchWheelList;
juce::Array<juce::Array<IntParam>> afterTouchList;
juce::Array<juce::Array<IntParam>> channelPressureList;

struct Controller {
uint8_t channel;
double timeSec;
uint8_t number;
uint8_t value;

int event;
};
juce::Array<std::unordered_map<uint8_t, juce::Array<Controller>>> controllerList;

struct Misc {
uint8_t channel;
double timeSec;

juce::MidiMessage message;

int event;
};
juce::Array<juce::Array<Misc>> miscList;
};

0 comments on commit a11e9c2

Please sign in to comment.