Skip to content

Commit

Permalink
Added channel pressure aftertouch.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtytel committed Mar 19, 2018
1 parent 559f5f1 commit 756e767
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mopo/src/voice_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,13 @@ namespace mopo {
}
}

void VoiceHandler::setChannelAftertouch(int channel, mopo_float aftertouch, int sample) {
for (Voice* voice : active_voices_) {
if (voice->state().channel == channel)
voice->setAftertouch(aftertouch, sample);
}
}

void VoiceHandler::setPolyphony(size_t polyphony) {
while (all_voices_.size() < polyphony) {
Voice* new_voice = createVoice();
Expand Down
1 change: 1 addition & 0 deletions mopo/src/voice_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ namespace mopo {
int sample = 0, int channel = 0) override;
virtual VoiceEvent noteOff(mopo_float note, int sample = 0) override;
void setAftertouch(mopo_float note, mopo_float aftertouch, int sample = 0);
void setChannelAftertouch(int channel, mopo_float aftertouch, int sample = 0);
void sustainOn();
void sustainOff(int sample = 0);

Expand Down
5 changes: 5 additions & 0 deletions src/common/midi_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ void MidiManager::processMidiMessage(const MidiMessage& midi_message, int sample
mopo::mopo_float value = (1.0 * midi_message.getAfterTouchValue()) / mopo::MIDI_SIZE;
engine_->setAftertouch(note, value);
}
else if (midi_message.isChannelPressure()) {
int channel = midi_message.getChannel();
mopo::mopo_float value = midi_message.getChannelPressureValue() / (mopo::MIDI_SIZE - 1.0f);
engine_->setChannelAftertouch(channel, value);
}
else if (midi_message.isPitchWheel()) {
double percent = (1.0 * midi_message.getPitchWheelValue()) / PITCH_WHEEL_RESOLUTION;
double value = 2 * percent - 1.0;
Expand Down
4 changes: 4 additions & 0 deletions src/synthesis/helm_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,10 @@ namespace mopo {
voice_handler_->setAftertouch(note, value, sample);
}

void HelmEngine::setChannelAftertouch(int channel, mopo_float value, int sample) {
voice_handler_->setChannelAftertouch(channel, value, sample);
}

void HelmEngine::setBpm(mopo_float bpm) {
mopo_float bps = bpm / 60.0;
if (bps_->value() != bps)
Expand Down
1 change: 1 addition & 0 deletions src/synthesis/helm_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ namespace mopo {
void setBpm(mopo_float bpm);
void correctToTime(mopo_float samples) override;
void setAftertouch(mopo_float note, mopo_float value, int sample = 0);
void setChannelAftertouch(int channel, mopo_float value, int sample = 0);

// Sustain pedal events.
void sustainOn();
Expand Down

0 comments on commit 756e767

Please sign in to comment.