Browse Source

Fix my misguided use of static variables

tags/v0.5.0
ben 7 years ago
parent
commit
ce4b0e77b2
5 changed files with 26 additions and 19 deletions
  1. +17
    -14
      src/core/MidiClockToCV.cpp
  2. +1
    -1
      src/core/MidiIO.cpp
  3. +4
    -0
      src/core/MidiIO.hpp
  4. +1
    -1
      src/core/MidiToCV.cpp
  5. +3
    -3
      src/core/QuadMidiToCV.cpp

+ 17
- 14
src/core/MidiClockToCV.cpp View File

@@ -34,6 +34,20 @@ struct MIDIClockToCVInterface : MidiIO, Module {
bool reset = false;
int c_bar = 0;

/* Note this is in relation to the Midi clock's Tick (6x per 16th note).
* Therefore, e.g. the 2:3 is calculated:
*
* 24 (Ticks per quarter note) * 2 / 3 = 16
*
* Implying that every 16 midi clock ticks we need to send a pulse
* */
int ratios[] = {6, 8, 12, 16, 24, 32, 48, 96, 192};
int numratios = sizeof(ratios) / sizeof(*ratios);

/*
* Length of clock pulse
*/
float pulseTime = 0.05;


MIDIClockToCVInterface() : MidiIO(), Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {
@@ -74,19 +88,8 @@ struct MIDIClockToCVInterface : MidiIO, Module {
};

void MIDIClockToCVInterface::step() {
static float trigger_length = 0.05;
float sampleRate = engineGetSampleRate();

/* Note this is in relation to the Midi clock's Tick (6x per 16th note).
* Therefore, e.g. the 2:3 is calculated:
*
* 24 (Ticks per quarter note) * 2 / 3 = 16
*
* Implying that every 16 midi clock ticks we need to send a pulse
* */
static int ratios[] = {6, 8, 12, 16, 24, 32, 48, 96, 192};
static int numratios = sizeof(ratios) / sizeof(*ratios);

if (isPortOpen()) {
static std::vector<unsigned char> message;

@@ -107,7 +110,7 @@ void MIDIClockToCVInterface::step() {
}

if (reset) {
resetPulse.trigger(trigger_length);
resetPulse.trigger(pulseTime);
reset = false;
c_bar = 0;
clock1Pulse.time = 0.0;
@@ -126,11 +129,11 @@ void MIDIClockToCVInterface::step() {
*/
if (running) {
if (c_bar % ratios[clock1ratio] == 0) {
clock1Pulse.trigger(trigger_length);
clock1Pulse.trigger(pulseTime);
}

if (c_bar % ratios[clock2ratio] == 0) {
clock2Pulse.trigger(trigger_length);
clock2Pulse.trigger(pulseTime);
}
}



+ 1
- 1
src/core/MidiIO.cpp View File

@@ -50,7 +50,7 @@ void MidiIO::baseFromJson(json_t *rootJ) {

std::vector<std::string> MidiIO::getDevices() {
/* Note: we could also use an existing interface if one exists */
static RtMidiIn *m = new RtMidiIn();
RtMidiIn *m = new RtMidiIn();

std::vector<std::string> names = {};



+ 4
- 0
src/core/MidiIO.hpp View File

@@ -48,6 +48,10 @@ struct MidiInWrapper : RtMidiIn {
}
};

/**
* Note: MidiIO is not thread safe which might become
* important in the future
*/
struct MidiIO {
private:
static std::unordered_map<std::string, MidiInWrapper *> midiInMap;


+ 1
- 1
src/core/MidiToCV.cpp View File

@@ -84,7 +84,7 @@ void MIDIToCVInterface::resetMidi() {
}

void MIDIToCVInterface::step() {
static float sampleRate = engineGetSampleRate();
float sampleRate = engineGetSampleRate();
if (isPortOpen()) {
std::vector<unsigned char> message;


+ 3
- 3
src/core/QuadMidiToCV.cpp View File

@@ -94,11 +94,12 @@ void QuadMIDIToCVInterface::resetMidi() {
}

void QuadMIDIToCVInterface::step() {
static float sampleRate = engineGetSampleRate();
static int msgsProcessed = 0;
float sampleRate = engineGetSampleRate();

if (isPortOpen()) {
std::vector<unsigned char> message;
int msgsProcessed = 0;

// midiIn->getMessage returns empty vector if there are no messages in the queue
// NOTE: For the quadmidi we will process max 4 midi messages per step to avoid
@@ -109,7 +110,6 @@ void QuadMIDIToCVInterface::step() {
getMessage(&message);
msgsProcessed++;
}
msgsProcessed = 0;
}




Loading…
Cancel
Save