From 5c56dd1574bd62b5eac175354c3cf1f766f736ab Mon Sep 17 00:00:00 2001 From: jfrey Date: Fri, 1 Dec 2017 04:50:18 +0200 Subject: [PATCH 1/6] implementing channel pressure as aftertouch --- mopo/src/voice_handler.cpp | 19 +++++++++++++++++++ mopo/src/voice_handler.h | 3 ++- src/common/midi_manager.cpp | 17 +++++++++++++++++ src/synthesis/helm_engine.cpp | 6 ++++++ src/synthesis/helm_engine.h | 2 ++ 5 files changed, 46 insertions(+), 1 deletion(-) diff --git a/mopo/src/voice_handler.cpp b/mopo/src/voice_handler.cpp index ef3b664afa..9fc3f5ff29 100644 --- a/mopo/src/voice_handler.cpp +++ b/mopo/src/voice_handler.cpp @@ -18,6 +18,8 @@ #include "utils.h" +#include + namespace mopo { Voice::Voice(Processor* processor) : event_sample_(-1), @@ -291,6 +293,8 @@ namespace mopo { } void VoiceHandler::noteOn(mopo_float note, mopo_float velocity, int sample, int channel) { + + std::cout << "noteOn, note: " << note << ", sample: " << sample << ", channel: " << channel << "\n"; MOPO_ASSERT(sample >= 0 && sample < buffer_size_); MOPO_ASSERT(channel >= 0 && channel < NUM_MIDI_CHANNELS); @@ -342,6 +346,21 @@ namespace mopo { voice->setAftertouch(aftertouch, sample); } } + + void VoiceHandler::setPressure(mopo_float pressure, int channel, int sample) { + MOPO_ASSERT(channel >= 1 && channel <= mopo::NUM_MIDI_CHANNELS); + + std::cout << "helm handler pressure, channel: " << channel << "\n"; + for (Voice* voice : active_voices_) { + std::cout << "voice active note:" << voice->state().note << "\n"; + + std::cout << "voice active channel:" << voice->state().channel << "\n"; + + + if (voice->state().channel == channel) + voice->setAftertouch(pressure, sample); + } + } void VoiceHandler::setPolyphony(size_t polyphony) { while (all_voices_.size() < polyphony) { diff --git a/mopo/src/voice_handler.h b/mopo/src/voice_handler.h index a9e1001bb2..fc191e1ab2 100644 --- a/mopo/src/voice_handler.h +++ b/mopo/src/voice_handler.h @@ -67,7 +67,7 @@ namespace mopo { state_.last_note = last_note; state_.note_pressed = note_pressed; state_.channel = channel; - aftertouch_ = velocity; + aftertouch_ = 0; aftertouch_sample_ = sample; key_state_ = kHeld; } @@ -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 setPressure(mopo_float pressure, int channel = 0, int sample = 0); void sustainOn(); void sustainOff(int sample = 0); diff --git a/src/common/midi_manager.cpp b/src/common/midi_manager.cpp index 3539343919..5f7d525366 100644 --- a/src/common/midi_manager.cpp +++ b/src/common/midi_manager.cpp @@ -92,6 +92,10 @@ void MidiManager::removeNextBlockOfMessages(MidiBuffer& buffer, int num_samples) } void MidiManager::processMidiMessage(const MidiMessage& midi_message, int sample_position) { + + std::cout << "midi message: " << midi_message.getTimeStamp() << " -- " << midi_message.getDescription() << ", sample position: " << sample_position << "\n"; + + if (midi_message.isProgramChange()) { current_patch_ = midi_message.getProgramChangeNumber(); File patch = LoadSave::loadPatch(current_bank_, current_folder_, current_patch_, @@ -102,6 +106,7 @@ void MidiManager::processMidiMessage(const MidiMessage& midi_message, int sample } if (midi_message.isNoteOn()) { + std::cout << "note on velocity: " << (int)midi_message.getVelocity() << "\n"; engine_->noteOn(midi_message.getNoteNumber(), midi_message.getVelocity() / (mopo::MIDI_SIZE - 1.0), 0, midi_message.getChannel() - 1); @@ -114,11 +119,23 @@ void MidiManager::processMidiMessage(const MidiMessage& midi_message, int sample engine_->sustainOn(); else if (midi_message.isSustainPedalOff()) engine_->sustainOff(); + // "aftertouch" is pressure per note else if (midi_message.isAftertouch()) { + std::cout << "aftertouch\n"; mopo::mopo_float note = midi_message.getNoteNumber(); mopo::mopo_float value = (1.0 * midi_message.getAfterTouchValue()) / mopo::MIDI_SIZE; engine_->setAftertouch(note, value); } + // "pressure" is aftertouch for a whole channel (e.g. keyboard send only one value even if several keys are pressed) + else if (midi_message.isChannelPressure()) { + std::cout << "pressure: " << midi_message.getChannelPressureValue() << "\n"; + + mopo::mopo_float note = midi_message.getNoteNumber(); + mopo::mopo_float value = (1.0 * midi_message.getChannelPressureValue()) / (mopo::MIDI_SIZE - 1.0); + std::cout << "channel: " << midi_message.getChannel() << ", MIDI_SIZE:" << mopo::MIDI_SIZE << ", value: " << value << "\n"; + // channel - 1 as with NoteOn above + engine_->setPressure(value, midi_message.getChannel() - 1, sample_position); + } else if (midi_message.isPitchWheel()) { double percent = (1.0 * midi_message.getPitchWheelValue()) / PITCH_WHEEL_RESOLUTION; double value = 2 * percent - 1.0; diff --git a/src/synthesis/helm_engine.cpp b/src/synthesis/helm_engine.cpp index 894653cb48..e82f7ff101 100644 --- a/src/synthesis/helm_engine.cpp +++ b/src/synthesis/helm_engine.cpp @@ -26,6 +26,8 @@ #include #endif +#include + #define MAX_DELAY_SAMPLES 300000 namespace mopo { @@ -396,6 +398,10 @@ namespace mopo { void HelmEngine::setPitchWheel(mopo_float value, int channel) { voice_handler_->setPitchWheel(value, channel); } + + void HelmEngine::setPressure(mopo_float value, int channel, int sample) { + voice_handler_->setPressure(value, channel, sample); + } void HelmEngine::setAftertouch(mopo_float note, mopo_float value, int sample) { voice_handler_->setAftertouch(note, value, sample); diff --git a/src/synthesis/helm_engine.h b/src/synthesis/helm_engine.h index 2790446e3d..7afc89048b 100644 --- a/src/synthesis/helm_engine.h +++ b/src/synthesis/helm_engine.h @@ -59,6 +59,8 @@ 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 setPressure(mopo_float value, int channel = 0, int sample = 0); + // Sustain pedal events. void sustainOn(); From f2b27bc23ec8318d89d62f27e15019ae5905397d Mon Sep 17 00:00:00 2001 From: jfrey Date: Fri, 1 Dec 2017 06:06:02 +0200 Subject: [PATCH 2/6] trying to pass aftertouch to arpeggiator --- mopo/src/arpeggiator.cpp | 20 ++++++++++++++------ mopo/src/arpeggiator.h | 6 ++++-- mopo/src/note_handler.h | 2 +- mopo/src/voice_handler.cpp | 6 +++--- mopo/src/voice_handler.h | 6 +++--- src/synthesis/helm_engine.cpp | 6 +++--- src/synthesis/helm_engine.h | 2 +- src/synthesis/helm_voice_handler.cpp | 4 ++-- src/synthesis/helm_voice_handler.h | 2 +- 9 files changed, 32 insertions(+), 22 deletions(-) diff --git a/mopo/src/arpeggiator.cpp b/mopo/src/arpeggiator.cpp index 1aa77866c0..ae36db6aa3 100644 --- a/mopo/src/arpeggiator.cpp +++ b/mopo/src/arpeggiator.cpp @@ -20,6 +20,7 @@ #include #include +#include namespace mopo { @@ -55,18 +56,19 @@ namespace mopo { } // Check if it's time to play the next note. + // FIXME: handle channel if (getNumNotes() && new_phase >= 1) { int offset = utils::iclamp((1 - phase_) / delta_phase, 0, buffer_size_ - 1); - std::pair note = getNextNote(); - note_handler_->noteOn(note.first, note.second, offset); - last_played_note_ = note.first; + std::tuple note = getNextNote(); + note_handler_->noteOn(std::get<0>(note), std::get<1>(note), offset, 0, std::get<2>(note)); + last_played_note_ = std::get<0>(note); phase_ = new_phase - 1.0; } else phase_ = new_phase; } - std::pair Arpeggiator::getNextNote() { + std::tuple Arpeggiator::getNextNote() { int octaves = utils::imax(1, input(kOctaves)->at(0)); Pattern type = static_cast(static_cast(input(kPattern)->at(0))); @@ -115,7 +117,8 @@ namespace mopo { mopo_float base_note = pattern->at(note_index_); mopo_float note = base_note + mopo::NOTES_PER_OCTAVE * current_octave_; mopo_float velocity = active_notes_[base_note]; - return std::pair(note, velocity); + mopo_float aftertouch = aftertouch_[base_note]; + return std::tuple(note, velocity, aftertouch); } CircularQueue& Arpeggiator::getPressedNotes() { @@ -152,6 +155,7 @@ namespace mopo { void Arpeggiator::allNotesOff(int sample) { active_notes_.clear(); + aftertouch_.clear(); pressed_notes_.clear(); sustained_notes_.clear(); ascending_.clear(); @@ -160,7 +164,9 @@ namespace mopo { note_handler_->allNotesOff(); } - void Arpeggiator::noteOn(mopo_float note, mopo_float velocity, int sample, int channel) { + void Arpeggiator::noteOn(mopo_float note, mopo_float velocity, int sample, int channel, mopo_float aftertouch) { + + std::cout << "arp noton, velocity: " << velocity << ", channel: " << channel << ", aftertouch: " << aftertouch << "\n"; if (active_notes_.count(note)) return; if (pressed_notes_.size() == 0) { @@ -169,6 +175,7 @@ namespace mopo { phase_ = 1.0; } active_notes_[note] = velocity; + aftertouch_[note] = aftertouch; pressed_notes_.push_back(note); addNoteToPatterns(note); } @@ -181,6 +188,7 @@ namespace mopo { sustained_notes_.push_back(note); else { active_notes_.erase(note); + aftertouch_.erase(note); removeNoteFromPatterns(note); } diff --git a/mopo/src/arpeggiator.h b/mopo/src/arpeggiator.h index 699ef873e9..1f48b7a27f 100644 --- a/mopo/src/arpeggiator.h +++ b/mopo/src/arpeggiator.h @@ -61,13 +61,13 @@ namespace mopo { int getNumNotes() { return pressed_notes_.size(); } CircularQueue& getPressedNotes(); - std::pair getNextNote(); + std::tuple getNextNote(); void addNoteToPatterns(mopo_float note); void removeNoteFromPatterns(mopo_float note); void allNotesOff(int sample = 0) override; void noteOn(mopo_float note, mopo_float velocity = 1, - int sample = 0, int channel = 0) override; + int sample = 0, int channel = 0, mopo_float aftertouch = 0) override; VoiceEvent noteOff(mopo_float note, int sample = 0) override; void sustainOn(); void sustainOff(); @@ -89,6 +89,8 @@ namespace mopo { std::vector decending_; std::map active_notes_; + std::map aftertouch_; + CircularQueue pressed_notes_; CircularQueue sustained_notes_; }; diff --git a/mopo/src/note_handler.h b/mopo/src/note_handler.h index a99ed32fef..db724aac62 100644 --- a/mopo/src/note_handler.h +++ b/mopo/src/note_handler.h @@ -27,7 +27,7 @@ namespace mopo { virtual ~NoteHandler() { } virtual void allNotesOff(int sample = 0) = 0; virtual void noteOn(mopo_float note, mopo_float velocity = 1, - int sample = 0, int channel = 0) = 0; + int sample = 0, int channel = 0, mopo_float aftertouch = 0) = 0; virtual VoiceEvent noteOff(mopo_float note, int sample = 0) = 0; }; } // namespace mopo diff --git a/mopo/src/voice_handler.cpp b/mopo/src/voice_handler.cpp index 9fc3f5ff29..1208ec1d42 100644 --- a/mopo/src/voice_handler.cpp +++ b/mopo/src/voice_handler.cpp @@ -292,9 +292,9 @@ namespace mopo { return 0; } - void VoiceHandler::noteOn(mopo_float note, mopo_float velocity, int sample, int channel) { + void VoiceHandler::noteOn(mopo_float note, mopo_float velocity, int sample, int channel, mopo_float aftertouch) { - std::cout << "noteOn, note: " << note << ", sample: " << sample << ", channel: " << channel << "\n"; + std::cout << "noteOn, note: " << note << ", sample: " << sample << ", channel: " << channel << "aftertouch: " << aftertouch << "\n"; MOPO_ASSERT(sample >= 0 && sample < buffer_size_); MOPO_ASSERT(channel >= 0 && channel < NUM_MIDI_CHANNELS); @@ -303,7 +303,7 @@ namespace mopo { if (last_played_note_ < 0) last_played_note_ = note; - voice->activate(note, velocity, last_played_note_, pressed_notes_.size(), sample, channel); + voice->activate(note, velocity, last_played_note_, pressed_notes_.size(), sample, channel, aftertouch); active_voices_.push_back(voice); last_played_note_ = note; } diff --git a/mopo/src/voice_handler.h b/mopo/src/voice_handler.h index fc191e1ab2..6350ddece8 100644 --- a/mopo/src/voice_handler.h +++ b/mopo/src/voice_handler.h @@ -59,7 +59,7 @@ namespace mopo { void activate(mopo_float note, mopo_float velocity, mopo_float last_note, int note_pressed = 0, - int sample = 0, int channel = 0) { + int sample = 0, int channel = 0, mopo_float aftertouch = 0) { event_sample_ = sample; state_.event = kVoiceOn; state_.note = note; @@ -67,7 +67,7 @@ namespace mopo { state_.last_note = last_note; state_.note_pressed = note_pressed; state_.channel = channel; - aftertouch_ = 0; + aftertouch_ = aftertouch; aftertouch_sample_ = sample; key_state_ = kHeld; } @@ -143,7 +143,7 @@ namespace mopo { void allNotesOff(int sample = 0) override; virtual void noteOn(mopo_float note, mopo_float velocity = 1, - int sample = 0, int channel = 0) override; + int sample = 0, int channel = 0, mopo_float aftertouch = 0) override; virtual VoiceEvent noteOff(mopo_float note, int sample = 0) override; void setAftertouch(mopo_float note, mopo_float aftertouch, int sample = 0); void setPressure(mopo_float pressure, int channel = 0, int sample = 0); diff --git a/src/synthesis/helm_engine.cpp b/src/synthesis/helm_engine.cpp index e82f7ff101..75f7a52c23 100644 --- a/src/synthesis/helm_engine.cpp +++ b/src/synthesis/helm_engine.cpp @@ -378,11 +378,11 @@ namespace mopo { arpeggiator_->allNotesOff(sample); } - void HelmEngine::noteOn(mopo_float note, mopo_float velocity, int sample, int channel) { + void HelmEngine::noteOn(mopo_float note, mopo_float velocity, int sample, int channel, mopo_float aftertouch) { if (arp_on_->value()) - arpeggiator_->noteOn(note, velocity, sample); + arpeggiator_->noteOn(note, velocity, sample, channel, aftertouch); else - voice_handler_->noteOn(note, velocity, sample, channel); + voice_handler_->noteOn(note, velocity, sample, channel, aftertouch); } VoiceEvent HelmEngine::noteOff(mopo_float note, int sample) { diff --git a/src/synthesis/helm_engine.h b/src/synthesis/helm_engine.h index 7afc89048b..ba88fa2e12 100644 --- a/src/synthesis/helm_engine.h +++ b/src/synthesis/helm_engine.h @@ -52,7 +52,7 @@ namespace mopo { // Keyboard events. void allNotesOff(int sample = 0) override; void noteOn(mopo_float note, mopo_float velocity = 1.0, - int sample = 0, int channel = 0) override; + int sample = 0, int channel = 0, mopo_float aftertouch = 0) override; VoiceEvent noteOff(mopo_float note, int sample = 0) override; void setModWheel(mopo_float value, int channel = 0); void setPitchWheel(mopo_float value, int channel = 0); diff --git a/src/synthesis/helm_voice_handler.cpp b/src/synthesis/helm_voice_handler.cpp index 97dddd2d07..d8b9eede3e 100644 --- a/src/synthesis/helm_voice_handler.cpp +++ b/src/synthesis/helm_voice_handler.cpp @@ -756,10 +756,10 @@ namespace mopo { } } - void HelmVoiceHandler::noteOn(mopo_float note, mopo_float velocity, int sample, int channel) { + void HelmVoiceHandler::noteOn(mopo_float note, mopo_float velocity, int sample, int channel, mopo_float aftertouch) { if (getPressedNotes().size() < polyphony() || legato_->value() == 0.0) note_retriggered_.trigger(note, sample); - VoiceHandler::noteOn(note, velocity, sample, channel); + VoiceHandler::noteOn(note, velocity, sample, channel, aftertouch); } VoiceEvent HelmVoiceHandler::noteOff(mopo_float note, int sample) { diff --git a/src/synthesis/helm_voice_handler.h b/src/synthesis/helm_voice_handler.h index ed521dd047..47a086115d 100644 --- a/src/synthesis/helm_voice_handler.h +++ b/src/synthesis/helm_voice_handler.h @@ -53,7 +53,7 @@ namespace mopo { void process() override; void noteOn(mopo_float note, mopo_float velocity = 1, - int sample = 0, int channel = 0) override; + int sample = 0, int channel = 0, mopo_float aftertouch = 0) override; VoiceEvent noteOff(mopo_float note, int sample = 0) override; bool shouldAccumulate(Output* output) override; void setModWheel(mopo_float value, int channel = 0); From a0a6939170cff4edfc536589036f5d2fa0e3bb02 Mon Sep 17 00:00:00 2001 From: jfrey Date: Fri, 1 Dec 2017 06:57:26 +0200 Subject: [PATCH 3/6] fix aftertouch / presure for arpeggiator --- mopo/src/arpeggiator.cpp | 22 ++++++++++++++++++++++ mopo/src/arpeggiator.h | 5 +++++ mopo/src/voice_handler.cpp | 2 +- src/synthesis/helm_engine.cpp | 4 ++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/mopo/src/arpeggiator.cpp b/mopo/src/arpeggiator.cpp index ae36db6aa3..19179bed08 100644 --- a/mopo/src/arpeggiator.cpp +++ b/mopo/src/arpeggiator.cpp @@ -117,6 +117,7 @@ namespace mopo { mopo_float base_note = pattern->at(note_index_); mopo_float note = base_note + mopo::NOTES_PER_OCTAVE * current_octave_; mopo_float velocity = active_notes_[base_note]; + std::cout << "nextnote. note_index " << note_index_ << ", base note: " << base_note << "\n"; mopo_float aftertouch = aftertouch_[base_note]; return std::tuple(note, velocity, aftertouch); } @@ -195,4 +196,25 @@ namespace mopo { pressed_notes_.remove(note); return kVoiceOff; } + + void Arpeggiator::setAftertouch(mopo_float note, mopo_float aftertouch, int sample) { + for (const auto &n : pressed_notes_) { + std::cout << "note: " << n << "\n"; + if (n == note) { + aftertouch_[n] = aftertouch; + } + } + } + + void Arpeggiator::setPressure(mopo_float pressure, int channel, int sample) { + MOPO_ASSERT(channel >= 1 && channel <= mopo::NUM_MIDI_CHANNELS); + + std::cout << "arp setpress, nb pressed: " << getNumNotes() << "\n"; + + // FIXME: check for channel + for (const auto &n : pressed_notes_) { + std::cout << "note: " << n << "\n"; + aftertouch_[n] = pressure; + } + } } // namespace mopo diff --git a/mopo/src/arpeggiator.h b/mopo/src/arpeggiator.h index 1f48b7a27f..4b106e47c7 100644 --- a/mopo/src/arpeggiator.h +++ b/mopo/src/arpeggiator.h @@ -71,6 +71,10 @@ namespace mopo { VoiceEvent noteOff(mopo_float note, int sample = 0) override; void sustainOn(); void sustainOff(); + + void setAftertouch(mopo_float note, mopo_float aftertouch, int sample = 0); + void setPressure(mopo_float pressure, int channel = 0, int sample = 0); + private: Arpeggiator() : Processor(0, 0) { } @@ -93,6 +97,7 @@ namespace mopo { CircularQueue pressed_notes_; CircularQueue sustained_notes_; + }; } // namespace mopo diff --git a/mopo/src/voice_handler.cpp b/mopo/src/voice_handler.cpp index 1208ec1d42..4d6fdf1fd7 100644 --- a/mopo/src/voice_handler.cpp +++ b/mopo/src/voice_handler.cpp @@ -327,7 +327,7 @@ namespace mopo { pressed_notes_.pop_back(); pressed_notes_.push_front(old_note); new_voice->activate(old_note, voice->state().velocity, last_played_note_, - pressed_notes_.size() + 1, sample); + pressed_notes_.size() + 1, sample); last_played_note_ = old_note; voice_event = kVoiceReset; diff --git a/src/synthesis/helm_engine.cpp b/src/synthesis/helm_engine.cpp index 75f7a52c23..b8368c885b 100644 --- a/src/synthesis/helm_engine.cpp +++ b/src/synthesis/helm_engine.cpp @@ -400,10 +400,14 @@ namespace mopo { } void HelmEngine::setPressure(mopo_float value, int channel, int sample) { + if (arp_on_->value()) + arpeggiator_->setPressure(value, channel, sample); voice_handler_->setPressure(value, channel, sample); } void HelmEngine::setAftertouch(mopo_float note, mopo_float value, int sample) { + if (arp_on_->value()) + arpeggiator_->setAftertouch(note, value, sample); voice_handler_->setAftertouch(note, value, sample); } From b79b402c289fb33116b21d1558c1ea28f1ab14c4 Mon Sep 17 00:00:00 2001 From: jfrey Date: Fri, 1 Dec 2017 07:18:27 +0200 Subject: [PATCH 4/6] arpeggiator pressure: take into account channel --- mopo/src/arpeggiator.cpp | 21 ++++++++++++++------- mopo/src/arpeggiator.h | 4 +++- src/synthesis/helm_engine.cpp | 1 + 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/mopo/src/arpeggiator.cpp b/mopo/src/arpeggiator.cpp index 19179bed08..00bc9bf88b 100644 --- a/mopo/src/arpeggiator.cpp +++ b/mopo/src/arpeggiator.cpp @@ -59,8 +59,8 @@ namespace mopo { // FIXME: handle channel if (getNumNotes() && new_phase >= 1) { int offset = utils::iclamp((1 - phase_) / delta_phase, 0, buffer_size_ - 1); - std::tuple note = getNextNote(); - note_handler_->noteOn(std::get<0>(note), std::get<1>(note), offset, 0, std::get<2>(note)); + std::tuple note = getNextNote(); + note_handler_->noteOn(std::get<0>(note), std::get<1>(note), offset, std::get<2>(note), std::get<3>(note)); last_played_note_ = std::get<0>(note); phase_ = new_phase - 1.0; } @@ -68,7 +68,7 @@ namespace mopo { phase_ = new_phase; } - std::tuple Arpeggiator::getNextNote() { + std::tuple Arpeggiator::getNextNote() { int octaves = utils::imax(1, input(kOctaves)->at(0)); Pattern type = static_cast(static_cast(input(kPattern)->at(0))); @@ -118,8 +118,10 @@ namespace mopo { mopo_float note = base_note + mopo::NOTES_PER_OCTAVE * current_octave_; mopo_float velocity = active_notes_[base_note]; std::cout << "nextnote. note_index " << note_index_ << ", base note: " << base_note << "\n"; + int channel = channel_[base_note]; mopo_float aftertouch = aftertouch_[base_note]; - return std::tuple(note, velocity, aftertouch); + + return std::tuple(note, velocity, channel, aftertouch); } CircularQueue& Arpeggiator::getPressedNotes() { @@ -156,6 +158,7 @@ namespace mopo { void Arpeggiator::allNotesOff(int sample) { active_notes_.clear(); + channel_.clear(); aftertouch_.clear(); pressed_notes_.clear(); sustained_notes_.clear(); @@ -176,6 +179,7 @@ namespace mopo { phase_ = 1.0; } active_notes_[note] = velocity; + channel_[note] = channel; aftertouch_[note] = aftertouch; pressed_notes_.push_back(note); addNoteToPatterns(note); @@ -189,6 +193,7 @@ namespace mopo { sustained_notes_.push_back(note); else { active_notes_.erase(note); + channel_.erase(note); aftertouch_.erase(note); removeNoteFromPatterns(note); } @@ -198,6 +203,7 @@ namespace mopo { } void Arpeggiator::setAftertouch(mopo_float note, mopo_float aftertouch, int sample) { + // TODO: take channel into account for (const auto &n : pressed_notes_) { std::cout << "note: " << n << "\n"; if (n == note) { @@ -211,10 +217,11 @@ namespace mopo { std::cout << "arp setpress, nb pressed: " << getNumNotes() << "\n"; - // FIXME: check for channel for (const auto &n : pressed_notes_) { - std::cout << "note: " << n << "\n"; - aftertouch_[n] = pressure; + std::cout << "note: " << n << " in channel: " << channel_[n] << "\n"; + if (channel_[n] == channel) { + aftertouch_[n] = pressure; + } } } } // namespace mopo diff --git a/mopo/src/arpeggiator.h b/mopo/src/arpeggiator.h index 4b106e47c7..52e8652142 100644 --- a/mopo/src/arpeggiator.h +++ b/mopo/src/arpeggiator.h @@ -61,7 +61,8 @@ namespace mopo { int getNumNotes() { return pressed_notes_.size(); } CircularQueue& getPressedNotes(); - std::tuple getNextNote(); + // tuple: note, velocity, channel, aftertouch + std::tuple getNextNote(); void addNoteToPatterns(mopo_float note); void removeNoteFromPatterns(mopo_float note); @@ -93,6 +94,7 @@ namespace mopo { std::vector decending_; std::map active_notes_; + std::map channel_; std::map aftertouch_; CircularQueue pressed_notes_; diff --git a/src/synthesis/helm_engine.cpp b/src/synthesis/helm_engine.cpp index b8368c885b..ae565cd2e4 100644 --- a/src/synthesis/helm_engine.cpp +++ b/src/synthesis/helm_engine.cpp @@ -406,6 +406,7 @@ namespace mopo { } void HelmEngine::setAftertouch(mopo_float note, mopo_float value, int sample) { + // TODO: take channel into account if (arp_on_->value()) arpeggiator_->setAftertouch(note, value, sample); voice_handler_->setAftertouch(note, value, sample); From 706778cf3311a73e2b2da554841daebac106aafc Mon Sep 17 00:00:00 2001 From: jfrey Date: Fri, 1 Dec 2017 19:54:12 +0200 Subject: [PATCH 5/6] cleanup debug info --- mopo/src/arpeggiator.cpp | 11 +---------- mopo/src/voice_handler.cpp | 13 +------------ src/common/midi_manager.cpp | 12 ++---------- src/synthesis/helm_engine.cpp | 2 -- src/synthesis/helm_engine.h | 1 - 5 files changed, 4 insertions(+), 35 deletions(-) diff --git a/mopo/src/arpeggiator.cpp b/mopo/src/arpeggiator.cpp index 00bc9bf88b..068429ef9e 100644 --- a/mopo/src/arpeggiator.cpp +++ b/mopo/src/arpeggiator.cpp @@ -20,7 +20,6 @@ #include #include -#include namespace mopo { @@ -117,7 +116,6 @@ namespace mopo { mopo_float base_note = pattern->at(note_index_); mopo_float note = base_note + mopo::NOTES_PER_OCTAVE * current_octave_; mopo_float velocity = active_notes_[base_note]; - std::cout << "nextnote. note_index " << note_index_ << ", base note: " << base_note << "\n"; int channel = channel_[base_note]; mopo_float aftertouch = aftertouch_[base_note]; @@ -169,8 +167,6 @@ namespace mopo { } void Arpeggiator::noteOn(mopo_float note, mopo_float velocity, int sample, int channel, mopo_float aftertouch) { - - std::cout << "arp noton, velocity: " << velocity << ", channel: " << channel << ", aftertouch: " << aftertouch << "\n"; if (active_notes_.count(note)) return; if (pressed_notes_.size() == 0) { @@ -205,7 +201,6 @@ namespace mopo { void Arpeggiator::setAftertouch(mopo_float note, mopo_float aftertouch, int sample) { // TODO: take channel into account for (const auto &n : pressed_notes_) { - std::cout << "note: " << n << "\n"; if (n == note) { aftertouch_[n] = aftertouch; } @@ -213,12 +208,8 @@ namespace mopo { } void Arpeggiator::setPressure(mopo_float pressure, int channel, int sample) { - MOPO_ASSERT(channel >= 1 && channel <= mopo::NUM_MIDI_CHANNELS); - - std::cout << "arp setpress, nb pressed: " << getNumNotes() << "\n"; - + MOPO_ASSERT(channel >= 1 && channel <= mopo::NUM_MIDI_CHANNELS); for (const auto &n : pressed_notes_) { - std::cout << "note: " << n << " in channel: " << channel_[n] << "\n"; if (channel_[n] == channel) { aftertouch_[n] = pressure; } diff --git a/mopo/src/voice_handler.cpp b/mopo/src/voice_handler.cpp index 4d6fdf1fd7..d94db9055b 100644 --- a/mopo/src/voice_handler.cpp +++ b/mopo/src/voice_handler.cpp @@ -18,8 +18,6 @@ #include "utils.h" -#include - namespace mopo { Voice::Voice(Processor* processor) : event_sample_(-1), @@ -293,8 +291,6 @@ namespace mopo { } void VoiceHandler::noteOn(mopo_float note, mopo_float velocity, int sample, int channel, mopo_float aftertouch) { - - std::cout << "noteOn, note: " << note << ", sample: " << sample << ", channel: " << channel << "aftertouch: " << aftertouch << "\n"; MOPO_ASSERT(sample >= 0 && sample < buffer_size_); MOPO_ASSERT(channel >= 0 && channel < NUM_MIDI_CHANNELS); @@ -349,14 +345,7 @@ namespace mopo { void VoiceHandler::setPressure(mopo_float pressure, int channel, int sample) { MOPO_ASSERT(channel >= 1 && channel <= mopo::NUM_MIDI_CHANNELS); - - std::cout << "helm handler pressure, channel: " << channel << "\n"; - for (Voice* voice : active_voices_) { - std::cout << "voice active note:" << voice->state().note << "\n"; - - std::cout << "voice active channel:" << voice->state().channel << "\n"; - - + for (Voice* voice : active_voices_) { if (voice->state().channel == channel) voice->setAftertouch(pressure, sample); } diff --git a/src/common/midi_manager.cpp b/src/common/midi_manager.cpp index 5f7d525366..6724b43729 100644 --- a/src/common/midi_manager.cpp +++ b/src/common/midi_manager.cpp @@ -91,11 +91,7 @@ void MidiManager::removeNextBlockOfMessages(MidiBuffer& buffer, int num_samples) midi_collector_.removeNextBlockOfMessages(buffer, num_samples); } -void MidiManager::processMidiMessage(const MidiMessage& midi_message, int sample_position) { - - std::cout << "midi message: " << midi_message.getTimeStamp() << " -- " << midi_message.getDescription() << ", sample position: " << sample_position << "\n"; - - +void MidiManager::processMidiMessage(const MidiMessage& midi_message, int sample_position) { if (midi_message.isProgramChange()) { current_patch_ = midi_message.getProgramChangeNumber(); File patch = LoadSave::loadPatch(current_bank_, current_folder_, current_patch_, @@ -106,7 +102,6 @@ void MidiManager::processMidiMessage(const MidiMessage& midi_message, int sample } if (midi_message.isNoteOn()) { - std::cout << "note on velocity: " << (int)midi_message.getVelocity() << "\n"; engine_->noteOn(midi_message.getNoteNumber(), midi_message.getVelocity() / (mopo::MIDI_SIZE - 1.0), 0, midi_message.getChannel() - 1); @@ -121,18 +116,15 @@ void MidiManager::processMidiMessage(const MidiMessage& midi_message, int sample engine_->sustainOff(); // "aftertouch" is pressure per note else if (midi_message.isAftertouch()) { - std::cout << "aftertouch\n"; mopo::mopo_float note = midi_message.getNoteNumber(); mopo::mopo_float value = (1.0 * midi_message.getAfterTouchValue()) / mopo::MIDI_SIZE; engine_->setAftertouch(note, value); } // "pressure" is aftertouch for a whole channel (e.g. keyboard send only one value even if several keys are pressed) + // TODO: create a separate modifier else if (midi_message.isChannelPressure()) { - std::cout << "pressure: " << midi_message.getChannelPressureValue() << "\n"; - mopo::mopo_float note = midi_message.getNoteNumber(); mopo::mopo_float value = (1.0 * midi_message.getChannelPressureValue()) / (mopo::MIDI_SIZE - 1.0); - std::cout << "channel: " << midi_message.getChannel() << ", MIDI_SIZE:" << mopo::MIDI_SIZE << ", value: " << value << "\n"; // channel - 1 as with NoteOn above engine_->setPressure(value, midi_message.getChannel() - 1, sample_position); } diff --git a/src/synthesis/helm_engine.cpp b/src/synthesis/helm_engine.cpp index ae565cd2e4..d638a38834 100644 --- a/src/synthesis/helm_engine.cpp +++ b/src/synthesis/helm_engine.cpp @@ -26,8 +26,6 @@ #include #endif -#include - #define MAX_DELAY_SAMPLES 300000 namespace mopo { diff --git a/src/synthesis/helm_engine.h b/src/synthesis/helm_engine.h index ba88fa2e12..b8966168fb 100644 --- a/src/synthesis/helm_engine.h +++ b/src/synthesis/helm_engine.h @@ -61,7 +61,6 @@ namespace mopo { void setAftertouch(mopo_float note, mopo_float value, int sample = 0); void setPressure(mopo_float value, int channel = 0, int sample = 0); - // Sustain pedal events. void sustainOn(); void sustainOff(); From 93fb9b3b9d1c3b25691a7c3d56d62b94803baa73 Mon Sep 17 00:00:00 2001 From: jfrey Date: Tue, 9 Jan 2018 05:46:13 +0200 Subject: [PATCH 6/6] fixing channel number assertion --- mopo/src/arpeggiator.cpp | 2 +- mopo/src/voice_handler.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mopo/src/arpeggiator.cpp b/mopo/src/arpeggiator.cpp index 068429ef9e..f5517607f3 100644 --- a/mopo/src/arpeggiator.cpp +++ b/mopo/src/arpeggiator.cpp @@ -208,7 +208,7 @@ namespace mopo { } void Arpeggiator::setPressure(mopo_float pressure, int channel, int sample) { - MOPO_ASSERT(channel >= 1 && channel <= mopo::NUM_MIDI_CHANNELS); + MOPO_ASSERT(channel >= 0 && channel <= mopo::NUM_MIDI_CHANNELS); for (const auto &n : pressed_notes_) { if (channel_[n] == channel) { aftertouch_[n] = pressure; diff --git a/mopo/src/voice_handler.cpp b/mopo/src/voice_handler.cpp index d94db9055b..78d50bcb59 100644 --- a/mopo/src/voice_handler.cpp +++ b/mopo/src/voice_handler.cpp @@ -344,7 +344,7 @@ namespace mopo { } void VoiceHandler::setPressure(mopo_float pressure, int channel, int sample) { - MOPO_ASSERT(channel >= 1 && channel <= mopo::NUM_MIDI_CHANNELS); + MOPO_ASSERT(channel >= 0 && channel <= mopo::NUM_MIDI_CHANNELS); for (Voice* voice : active_voices_) { if (voice->state().channel == channel) voice->setAftertouch(pressure, sample);