Skip to content

Commit

Permalink
Merge commit 'b24e1c373c7c54871d33247d40216e311dc00849' into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
hemmer committed Apr 28, 2024
2 parents bd1d36f + b24e1c3 commit 6ce2871
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## v2.7.1
* Midi Thing 2
* Remove -10 to 0 V configuration
* Add menu option to set all channels mode at once
* Fix appearance in module browser

## v2.7.0
* Midi Thing 2
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"slug": "Befaco",
"version": "2.7.0",
"version": "2.7.1",
"license": "GPL-3.0-or-later",
"name": "Befaco",
"brand": "Befaco",
Expand Down
39 changes: 29 additions & 10 deletions src/MidiThing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,16 @@ struct MidiThing : Module {
NOPORTMODE = 0,
MODE10V,
MODEPN5V,
MODENEG10V,
MODE8V,
MODE5V,

LASTPORTMODE
};

const char* cfgPortModeNames[7] = {
const char* cfgPortModeNames[6] = {
"No Mode",
"0/10v",
"-5/5v",
"-10/0v",
"0/8v",
"0/5v",
""
Expand Down Expand Up @@ -179,7 +177,13 @@ struct MidiThing : Module {
midiOut.sendMessage(msg);
// DEBUG("Predef %d msg request sent: %s", mergeOn, msg.toString().c_str());
}

void setVoltageModeOnHardwareAllChannels(PORTMODE_t outputMode_) {
for (int row = 0; row < 4; ++row) {
for (int col = 0; col < 3; ++col) {
setVoltageModeOnHardware(row, col, outputMode_);
}
}
}

void setVoltageModeOnHardware(uint8_t row, uint8_t col, PORTMODE_t outputMode_) {
uint8_t port = 3 * row + col;
Expand Down Expand Up @@ -243,7 +247,6 @@ struct MidiThing : Module {
switch (portModes[channel]) {
case MODE10V: return 0 - tol < voltage && voltage < 10 + tol;
case MODEPN5V: return -5 - tol < voltage && voltage < 5 + tol;
case MODENEG10V: return -10 - tol < voltage && voltage < 0 + tol;
case MODE8V: return 0 - tol < voltage && voltage < 8 + tol;
case MODE5V: return 0 - tol < voltage && voltage < 5 + tol;
default: return false;
Expand All @@ -254,7 +257,6 @@ struct MidiThing : Module {
switch (portModes[channel]) {
case MODE10V: return rescale(clamp(voltage, 0.f, 10.f), 0.f, +10.f, 0, 16383);
case MODEPN5V: return rescale(clamp(voltage, -5.f, 5.f), -5.f, +5.f, 0, 16383);
case MODENEG10V: return rescale(clamp(voltage, -10.f, 0.f), -10.f, +0.f, 0, 16383);
case MODE8V: return rescale(clamp(voltage, 0.f, 8.f), 0.f, +8.f, 0, 16383);
case MODE5V: return rescale(clamp(voltage, 0.f, 5.f), 0.f, +5.f, 0, 16383);
default: return 0;
Expand Down Expand Up @@ -405,7 +407,7 @@ struct MidiThingPort : BefacoInputPort {
std::string label = string::f("Voltage Mode Port %d", 3 * row + col + 1);

menu->addChild(createIndexSubmenuItem(label,
{"0 to 10v", "-5 to 5v", "-10 to 0v", "0 to 8v", "0 to 5v"},
{"0 to 10v", "-5 to 5v", "0 to 8v", "0 to 5v"},
[ = ]() {
return module->getVoltageMode(row, col);
},
Expand Down Expand Up @@ -485,10 +487,16 @@ struct LEDDisplay : LightWidget {

if (font && font->handle >= 0) {

std::string text = "?-?v"; // fallback if module not yet defined
std::string text;
if (module) {
text = module->cfgPortModeNames[module->getVoltageMode(row, col) + 1];
}
else {
// fallback if module not yet defined
const char* cfgPortModeNames[4] = {"0/10v", "-5/5v", "0/8v", "0/5v"};
const int randomModeForDisplay = rack::random::u32() % 4;
text = cfgPortModeNames[randomModeForDisplay];
}
char buffer[numChars + 1];
int l = text.size();
if (l > numChars)
Expand All @@ -515,9 +523,9 @@ struct LEDDisplay : LightWidget {

menu->addChild(createMenuLabel(string::f("Voltage mode port %d:", col + 3 * row + 1)));

const std::string labels[5] = {"0 to 10v", "-5 to 5v", "-10 to 0v", "0 to 8v", "0 to 5v"};
const std::string labels[4] = {"0 to 10v", "-5 to 5v", "0 to 8v", "0 to 5v"};

for (int i = 0; i < 5; ++i) {
for (int i = 0; i < 4; ++i) {
menu->addChild(createCheckMenuItem(labels[i], "",
[ = ]() {
return module->getVoltageMode(row, col) == i;
Expand Down Expand Up @@ -797,6 +805,17 @@ struct MidiThingWidget : ModuleWidget {

float updateRate = module->updateRates[module->updateRateIdx] / module->numActiveChannels;
menu->addChild(createMenuLabel(string::f("Per-channel MIDI update rate: %.3g Hz", updateRate)));

menu->addChild(createIndexSubmenuItem("Set mode for all channels",
{"0 to 10v", "-5 to 5v", "0 to 8v", "0 to 5v"},
[ = ]() {
return -1;
},
[ = ](int modeIdx) {
MidiThing::PORTMODE_t mode = (MidiThing::PORTMODE_t)(modeIdx + 1);
module->setVoltageModeOnHardwareAllChannels(mode);
}
));
}
};

Expand Down

0 comments on commit 6ce2871

Please sign in to comment.