Skip to content

Commit

Permalink
improve unlearn of midi and modulators
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechnobear committed Apr 17, 2019
1 parent c42e470 commit bc87264
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
16 changes: 10 additions & 6 deletions mec-kontrol/pd/kontrolrack/devices/KontrolDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ bool KontrolDevice::init() {
enableMenu(true);
modParamId_ = "";
modModuleId_ = "";
modSource_ = -1;
modulators_.clear();
for (const auto &m : modes_) {
if (m.second != nullptr) m.second->init();
Expand Down Expand Up @@ -106,6 +107,7 @@ void KontrolDevice::changed(Kontrol::ChangeSource src, const Kontrol::Rack &rack
if(modulators_.find(currentModuleId_) == modulators_.end()) {
modModuleId_ = module.id();
modParamId_ = param.id();
modSource_ = -1;
}
}

Expand Down Expand Up @@ -146,7 +148,9 @@ void KontrolDevice::loadModule(Kontrol::ChangeSource src, const Kontrol::Rack &r

void KontrolDevice::midiCC(unsigned num, unsigned value) {
if (midiLearnActive_) {
if (!modModuleId_.empty() && !modParamId_.empty()) {
if (!modModuleId_.empty() && !modParamId_.empty()
&& (modSource_ < 0 || modSource_ == num)
) {
auto rack = model()->getRack(currentRackId_);
if (rack != nullptr) {
if (value > 0) {
Expand All @@ -155,8 +159,7 @@ void KontrolDevice::midiCC(unsigned num, unsigned value) {
//std::cerr << "midiCC unlearn" << num << " " << modParamId_ << std::endl;
rack->removeMidiCCMapping(num, modModuleId_, modParamId_);
}
modParamId_ = "";
modModuleId_ = "";
modSource_ = num;
}
}
}
Expand All @@ -171,7 +174,9 @@ void KontrolDevice:: modulate(const std::string& src, unsigned bus, float value)
//TODO: when adding src dependent modulation, check to see what we should use for mod learn
if (modulationLearnActive_) {
modulators_.insert(src);
if (!modModuleId_.empty() && !modParamId_.empty()) {
if (!modModuleId_.empty() && !modParamId_.empty()
&& (modSource_ < 0 || modSource_ == bus)
) {
auto rack = model()->getRack(currentRackId_);
if (rack != nullptr) {
if (value > 0.1) {
Expand All @@ -181,8 +186,7 @@ void KontrolDevice:: modulate(const std::string& src, unsigned bus, float value)
//std::cerr << "modulation unlearn" << bus << " " << modParamId_ << std::endl;
rack->removeModulationMapping(src, bus, modModuleId_, modParamId_);
}
modParamId_ = "";
modModuleId_ = "";
modSource_ = bus;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions mec-kontrol/pd/kontrolrack/devices/KontrolDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,6 @@ class KontrolDevice : public Kontrol::KontrolCallback {

Kontrol::EntityId modParamId_;
Kontrol::EntityId modModuleId_;
int modSource_;
std::unordered_set<Kontrol::EntityId> modulators_;
};

0 comments on commit bc87264

Please sign in to comment.