Skip to content

Commit

Permalink
arpeggiator pressure: take into account channel
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrey-xx committed Dec 1, 2017
1 parent a0a6939 commit b79b402
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
21 changes: 14 additions & 7 deletions mopo/src/arpeggiator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ namespace mopo {
// FIXME: handle channel
if (getNumNotes() && new_phase >= 1) {
int offset = utils::iclamp((1 - phase_) / delta_phase, 0, buffer_size_ - 1);
std::tuple<mopo_float, mopo_float, mopo_float> note = getNextNote();
note_handler_->noteOn(std::get<0>(note), std::get<1>(note), offset, 0, std::get<2>(note));
std::tuple<mopo_float, mopo_float, int, mopo_float> 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;
}
else
phase_ = new_phase;
}

std::tuple<mopo_float, mopo_float, mopo_float> Arpeggiator::getNextNote() {
std::tuple<mopo_float, mopo_float, int, mopo_float> Arpeggiator::getNextNote() {
int octaves = utils::imax(1, input(kOctaves)->at(0));
Pattern type =
static_cast<Pattern>(static_cast<int>(input(kPattern)->at(0)));
Expand Down Expand Up @@ -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<mopo_float, mopo_float, mopo_float>(note, velocity, aftertouch);

return std::tuple<mopo_float, mopo_float, int, mopo_float>(note, velocity, channel, aftertouch);
}

CircularQueue<mopo_float>& Arpeggiator::getPressedNotes() {
Expand Down Expand Up @@ -156,6 +158,7 @@ namespace mopo {

void Arpeggiator::allNotesOff(int sample) {
active_notes_.clear();
channel_.clear();
aftertouch_.clear();
pressed_notes_.clear();
sustained_notes_.clear();
Expand All @@ -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);
Expand All @@ -189,6 +193,7 @@ namespace mopo {
sustained_notes_.push_back(note);
else {
active_notes_.erase(note);
channel_.erase(note);
aftertouch_.erase(note);
removeNoteFromPatterns(note);
}
Expand All @@ -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) {
Expand All @@ -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
4 changes: 3 additions & 1 deletion mopo/src/arpeggiator.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ namespace mopo {

int getNumNotes() { return pressed_notes_.size(); }
CircularQueue<mopo_float>& getPressedNotes();
std::tuple<mopo_float, mopo_float, mopo_float> getNextNote();
// tuple: note, velocity, channel, aftertouch
std::tuple<mopo_float, mopo_float, int, mopo_float> getNextNote();
void addNoteToPatterns(mopo_float note);
void removeNoteFromPatterns(mopo_float note);

Expand Down Expand Up @@ -93,6 +94,7 @@ namespace mopo {
std::vector<mopo_float> decending_;

std::map<mopo_float, mopo_float> active_notes_;
std::map<mopo_float, int> channel_;
std::map<mopo_float, mopo_float> aftertouch_;

CircularQueue<mopo_float> pressed_notes_;
Expand Down
1 change: 1 addition & 0 deletions src/synthesis/helm_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b79b402

Please sign in to comment.