Skip to content

Commit

Permalink
Run autoformatter on Core MIDI modules
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewBelt committed Dec 8, 2017
1 parent 5621953 commit e601177
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 83 deletions.
17 changes: 11 additions & 6 deletions src/core/MidiCCToCV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void MIDICCToCVInterface::resetMidi() {
for (int i = 0; i < NUM_OUTPUTS; i++) {
cc[i].val = 0;
cc[i].resetSync();
cc[i].tSmooth.set(0,0);
cc[i].tSmooth.set(0, 0);
}
};

Expand Down Expand Up @@ -147,7 +147,8 @@ void MIDICCToCVInterface::processMidi(std::vector<unsigned char> msg) {
cc[i].syncFirst = false;
if (data2 < cc[i].val + 2 && data2 > cc[i].val - 2) {
cc[i].sync = 0;
}else {
}
else {
cc[i].sync = absi(data2 - cc[i].val);
}
return;
Expand All @@ -156,7 +157,8 @@ void MIDICCToCVInterface::processMidi(std::vector<unsigned char> msg) {
if (cc[i].sync == 0) {
cc[i].val = data2;
cc[i].changed = true;
} else {
}
else {
cc[i].sync = absi(data2 - cc[i].val);
}
}
Expand Down Expand Up @@ -225,12 +227,14 @@ void CCTextField::onTextChange() {
text = "";
begin = end = 0;
module->cc[outNum].num = -1;
} else {
}
else {
module->cc[outNum].num = num;
module->cc[outNum].resetSync();
}

} catch (...) {
}
catch (...) {
text = "";
begin = end = 0;
module->cc[outNum].num = -1;
Expand Down Expand Up @@ -309,7 +313,8 @@ MIDICCToCVWidget::MIDICCToCVWidget() {

if ((i + 1) % 4 == 0) {
yPos += 47 + margin;
} else {
}
else {
yPos -= labelHeight + margin;
}
}
Expand Down
50 changes: 26 additions & 24 deletions src/core/MidiClockToCV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ struct MIDIClockToCVInterface : MidiIO, Module {

void resetMidi() override;

json_t *toJson() override{
json_t *toJson() override {
json_t *rootJ = json_object();
addBaseJson(rootJ);
json_object_set_new(rootJ, "clock1ratio", json_integer(clock1ratio));
json_object_set_new(rootJ, "clock2ratio", json_integer(clock2ratio));
return rootJ;
}

void fromJson(json_t *rootJ) override{
void fromJson(json_t *rootJ) override {
baseFromJson(rootJ);
json_t *c1rJ = json_object_get(rootJ, "clock1ratio");
if (c1rJ) {
Expand Down Expand Up @@ -185,18 +185,18 @@ void MIDIClockToCVInterface::resetMidi() {
void MIDIClockToCVInterface::processMidi(std::vector<unsigned char> msg) {

switch (msg[0]) {
case 0xfa:
start = true;
break;
case 0xfb:
cont = true;
break;
case 0xfc:
stop = true;
break;
case 0xf8:
tick = true;
break;
case 0xfa:
start = true;
break;
case 0xfb:
cont = true;
break;
case 0xfc:
stop = true;
break;
case 0xf8:
tick = true;
break;
}


Expand All @@ -218,13 +218,15 @@ struct ClockRatioItem : MenuItem {
struct ClockRatioChoice : ChoiceButton {
int *clockRatio;
const std::vector<std::string> ratioNames = {"Sixteenth note (1:4 ratio)", "Eighth note triplet (1:3 ratio)",
"Eighth note (1:2 ratio)", "Quarter note triplet (2:3 ratio)",
"Quarter note (tap speed)", "Half note triplet (4:3 ratio)",
"Half note (2:1 ratio)", "Whole note (4:1 ratio)",
"Two whole notes (8:1 ratio)"};
"Eighth note (1:2 ratio)", "Quarter note triplet (2:3 ratio)",
"Quarter note (tap speed)", "Half note triplet (4:3 ratio)",
"Half note (2:1 ratio)", "Whole note (4:1 ratio)",
"Two whole notes (8:1 ratio)"
};

const std::vector<std::string> ratioNames_short = {"1:4 ratio", "1:3 ratio", "1:2 ratio", "2:3 ratio", "1:1 ratio",
"4:3", "2:1 ratio", "4:1 ratio", "8:1 ratio"};
"4:3", "2:1 ratio", "4:1 ratio", "8:1 ratio"
};

void onAction(EventAction &e) override {
Menu *menu = gScene->createMenu();
Expand Down Expand Up @@ -270,7 +272,7 @@ MIDIClockToCVWidget::MIDIClockToCVWidget() {
label->box.pos = Vec(box.size.x - margin - 7 * 15, margin);
label->text = "MIDI Clk-CV";
addChild(label);
yPos = labelHeight*2;
yPos = labelHeight * 2;
}

{
Expand Down Expand Up @@ -320,8 +322,8 @@ MIDIClockToCVWidget::MIDIClockToCVWidget() {
addInput(createInput<PJ3410Port>(Vec(margin, yPos - 5), module, MIDIClockToCVInterface::CLOCK1_RATIO));
ClockRatioChoice *ratioChoice = new ClockRatioChoice();
ratioChoice->clockRatio = &module->clock1ratio;
ratioChoice->box.pos = Vec(int(box.size.x/3), yPos);
ratioChoice->box.size.x = int(box.size.x/1.5 - margin);
ratioChoice->box.pos = Vec(int(box.size.x / 3), yPos);
ratioChoice->box.size.x = int(box.size.x / 1.5 - margin);

addChild(ratioChoice);
yPos += ratioChoice->box.size.y + margin * 3;
Expand All @@ -344,8 +346,8 @@ MIDIClockToCVWidget::MIDIClockToCVWidget() {
addInput(createInput<PJ3410Port>(Vec(margin, yPos - 5), module, MIDIClockToCVInterface::CLOCK2_RATIO));
ClockRatioChoice *ratioChoice = new ClockRatioChoice();
ratioChoice->clockRatio = &module->clock2ratio;
ratioChoice->box.pos = Vec(int(box.size.x/3), yPos);
ratioChoice->box.size.x = int(box.size.x/1.5 - margin);
ratioChoice->box.pos = Vec(int(box.size.x / 3), yPos);
ratioChoice->box.size.x = int(box.size.x / 1.5 - margin);

addChild(ratioChoice);
yPos += ratioChoice->box.size.y + margin * 3;
Expand Down
3 changes: 2 additions & 1 deletion src/core/MidiIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ std::vector<std::string> MidiIO::getDevices() {
RtMidiIn *m;
try {
m = new RtMidiIn();
} catch (RtMidiError &error) {
}
catch (RtMidiError &error) {
warn("Failed to create RtMidiIn: %s", error.getMessage().c_str());
return names;
}
Expand Down
12 changes: 6 additions & 6 deletions src/core/MidiIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

using namespace rack;


struct IgnoreFlags {
bool midiSysex = true;
bool midiTime = true;
Expand All @@ -20,7 +21,6 @@ struct MidiMessage {
double timeStamp;

MidiMessage() : bytes(0), timeStamp(0.0) {};

};

/**
Expand Down Expand Up @@ -135,10 +135,10 @@ struct TransitionSmoother {
switch (m) {
case DELTA:
/* If the change is smaller, the transition phase is longer */
this->step = delta > 0 ? delta/l : -delta/l;
this->step = delta > 0 ? delta / l : -delta / l;
break;
case CONST:
this->step = 1.0/l;
this->step = 1.0 / l;
break;
}

Expand All @@ -153,13 +153,13 @@ struct TransitionSmoother {

switch (t) {
case SMOOTHSTEP:
next += delta*x*x*(3-2*x);
next += delta * x * x * (3 - 2 * x);
break;
case EXP:
next += delta*x*x;
next += delta * x * x;
break;
case LIN:
next += delta*x;
next += delta * x;
break;
}

Expand Down
9 changes: 6 additions & 3 deletions src/core/MidiTriggerToCV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,12 @@ void TriggerTextField::onTextChange() {
text = "";
begin = end = 0;
module->trigger[outNum].num = -1;
}else {
}
else {
module->trigger[outNum].num = num;
}
} catch (...) {
}
catch (...) {
text = "";
begin = end = 0;
module->trigger[outNum].num = -1;
Expand Down Expand Up @@ -271,7 +273,8 @@ MIDITriggerToCVWidget::MIDITriggerToCVWidget() {

if ((i + 1) % 4 == 0) {
yPos += 47 + margin;
} else {
}
else {
yPos -= labelHeight + margin;
}
}
Expand Down
87 changes: 44 additions & 43 deletions src/core/QuadMidiToCV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,40 +140,41 @@ void QuadMIDIToCVInterface::processMidi(std::vector<unsigned char> msg) {
return;

switch (status) {
// note off
case 0x8: {
// note off
case 0x8: {
gate = false;
}
break;
case 0x9: // note on
if (data2 > 0) {
gate = true;
}
else {
// For some reason, some keyboards send a "note on" event with a velocity of 0 to signal that the key has been released.
gate = false;
}
break;
case 0x9: // note on
if (data2 > 0) {
gate = true;
} else {
// For some reason, some keyboards send a "note on" event with a velocity of 0 to signal that the key has been released.
gate = false;
}
break;
case 0xa: // channel aftertouch
for (int i = 0; i < 4; i++) {
if (activeKeys[i].pitch == data1) {
activeKeys[i].at = data2;
}
break;
case 0xa: // channel aftertouch
for (int i = 0; i < 4; i++) {
if (activeKeys[i].pitch == data1) {
activeKeys[i].at = data2;
}
return;
case 0xb: // cc
if (data1 == 0x40) { // pedal
pedal = (data2 >= 64);
if (!pedal) {
open.clear();
for (int i = 0; i < 4; i++) {
activeKeys[i].gate = false;
open.push_back(i);
}
}
return;
case 0xb: // cc
if (data1 == 0x40) { // pedal
pedal = (data2 >= 64);
if (!pedal) {
open.clear();
for (int i = 0; i < 4; i++) {
activeKeys[i].gate = false;
open.push_back(i);
}
}
return;
default:
return;
}
return;
default:
return;
}

if (pedal && !gate) {
Expand Down Expand Up @@ -201,25 +202,25 @@ void QuadMIDIToCVInterface::processMidi(std::vector<unsigned char> msg) {
}

if (!activeKeys[0].gate && !activeKeys[1].gate &&
!activeKeys[2].gate && !activeKeys[3].gate) {
!activeKeys[2].gate && !activeKeys[3].gate) {
open.sort();
}


switch (mode) {
case RESET:
if (open.size() >= 4) {
for (int i = 0; i < 4; i++) {
activeKeys[i].gate = false;
open.push_back(i);
}
case RESET:
if (open.size() >= 4) {
for (int i = 0; i < 4; i++) {
activeKeys[i].gate = false;
open.push_back(i);
}
break;
case REASSIGN:
open.push_back(open.front());
break;
case ROTATE:
break;
}
break;
case REASSIGN:
open.push_back(open.front());
break;
case ROTATE:
break;
}

int next = open.front();
Expand Down Expand Up @@ -313,7 +314,7 @@ QuadMidiToCVWidget::QuadMidiToCVWidget() {
}

addParam(createParam<LEDButton>(Vec(12 * 15, labelHeight), module, QuadMIDIToCVInterface::RESET_PARAM, 0.0, 1.0,
0.0));
0.0));
addChild(createLight<SmallLight<RedLight>>(Vec(12 * 15 + 5, labelHeight + 5), module, QuadMIDIToCVInterface::RESET_LIGHT));
{
Label *label = new Label();
Expand Down

0 comments on commit e601177

Please sign in to comment.