summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2008-05-23 05:16:33 +0000
committerDavid Robillard <d@drobilla.net>2008-05-23 05:16:33 +0000
commit2c46e6a464d2ac5be8e16a62fba6f00924090ea8 (patch)
treedd5471166f91ad922e7b8f987a648558a88c45fc /src
parent0dbcca14bcbcb3aa7e7c0ae24934463a5973a651 (diff)
downloadingen-2c46e6a464d2ac5be8e16a62fba6f00924090ea8.tar.gz
ingen-2c46e6a464d2ac5be8e16a62fba6f00924090ea8.tar.bz2
ingen-2c46e6a464d2ac5be8e16a62fba6f00924090ea8.zip
Fix infinite loops (and jack death) on internal MIDI nodes (note, trigger, control).
git-svn-id: http://svn.drobilla.net/lad/ingen@1231 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/libs/engine/EventBuffer.hpp3
-rw-r--r--src/libs/engine/MidiControlNode.cpp9
-rw-r--r--src/libs/engine/MidiNoteNode.cpp32
-rw-r--r--src/libs/engine/MidiTriggerNode.cpp19
4 files changed, 30 insertions, 33 deletions
diff --git a/src/libs/engine/EventBuffer.hpp b/src/libs/engine/EventBuffer.hpp
index abb51012..148b5420 100644
--- a/src/libs/engine/EventBuffer.hpp
+++ b/src/libs/engine/EventBuffer.hpp
@@ -57,6 +57,7 @@ public:
inline void clear() { reset(_this_nframes); }
inline void reset(SampleCount nframes) {
//std::cerr << this << " reset" << std::endl;
+ _this_nframes = nframes;
_latest_frames = 0;
_latest_subframes = 0;
_buf->event_count = 0;
@@ -93,8 +94,6 @@ private:
uint32_t _latest_frames; ///< Latest time of all events (frames)
uint32_t _latest_subframes; ///< Latest time of all events (subframes)
uint32_t _this_nframes; ///< Current cycle nframes
-
-
};
diff --git a/src/libs/engine/MidiControlNode.cpp b/src/libs/engine/MidiControlNode.cpp
index 263180f7..45f5f034 100644
--- a/src/libs/engine/MidiControlNode.cpp
+++ b/src/libs/engine/MidiControlNode.cpp
@@ -75,16 +75,15 @@ MidiControlNode::process(ProcessContext& context)
uint32_t subframes = 0;
uint16_t type = 0;
uint16_t size = 0;
- uint8_t* data = NULL;
+ uint8_t* buf = NULL;
EventBuffer* const midi_in = (EventBuffer*)_midi_in_port->buffer(0);
assert(midi_in->this_nframes() == context.nframes());
- while (midi_in->get_event(&frames, &subframes, &type, &size, &data) < context.nframes()) {
-
+ while (midi_in->get_event(&frames, &subframes, &type, &size, &buf)) {
// FIXME: type
- if (size >= 3 && (data[0] & 0xF0) == MIDI_CMD_CONTROL)
- control(data[1], data[2], (SampleCount)frames);
+ if (size >= 3 && (buf[0] & 0xF0) == MIDI_CMD_CONTROL)
+ control(buf[1], buf[2], (SampleCount)frames);
midi_in->increment();
}
diff --git a/src/libs/engine/MidiNoteNode.cpp b/src/libs/engine/MidiNoteNode.cpp
index 531c48cb..729cf2c3 100644
--- a/src/libs/engine/MidiNoteNode.cpp
+++ b/src/libs/engine/MidiNoteNode.cpp
@@ -120,7 +120,7 @@ MidiNoteNode::process(ProcessContext& context)
uint32_t subframes = 0;
uint16_t type = 0;
uint16_t size = 0;
- unsigned char* buffer = NULL;
+ unsigned char* buf = NULL;
EventBuffer* const midi_in = (EventBuffer*)_midi_in_port->buffer(0);
assert(midi_in->this_nframes() == context.nframes());
@@ -128,34 +128,34 @@ MidiNoteNode::process(ProcessContext& context)
//cerr << path() << " # input events: " << midi_in->event_count() << endl;
if (midi_in->event_count() > 0)
- while (midi_in->get_event(&frames, &subframes, &type, &size, &buffer) < context.nframes()) {
+ while (midi_in->get_event(&frames, &subframes, &type, &size, &buf)) {
- cout << "EVENT TYPE " << type << " @ " << frames << "." << subframes << ": ";
+ /*cout << "EVENT TYPE " << type << " @ " << frames << "." << subframes << ": ";
for (uint16_t i = 0; i < size; ++i)
- cout << (int)((char)buffer[i]) << " ";
- cout << endl;
+ cout << (int)((char)buf[i]) << " ";
+ cout << endl;*/
const FrameTime time = context.start() + (FrameTime)frames;
if (size >= 3) {
- switch (buffer[0] & 0xF0) {
+ switch (buf[0] & 0xF0) {
case MIDI_CMD_NOTE_ON:
- if (buffer[2] == 0)
- note_off(buffer[1], time, context);
+ if (buf[2] == 0)
+ note_off(buf[1], time, context);
else
- note_on(buffer[1], buffer[2], time, context);
+ note_on(buf[1], buf[2], time, context);
break;
case MIDI_CMD_NOTE_OFF:
- note_off(buffer[1], time, context);
+ note_off(buf[1], time, context);
break;
case MIDI_CMD_CONTROL:
- switch (buffer[1]) {
+ switch (buf[1]) {
case MIDI_CTL_ALL_NOTES_OFF:
case MIDI_CTL_ALL_SOUNDS_OFF:
all_notes_off(time, context);
break;
case MIDI_CTL_SUSTAIN:
- if (buffer[2] > 63)
+ if (buf[2] > 63)
sustain_on(time, context);
else
sustain_off(time, context);
@@ -164,16 +164,16 @@ MidiNoteNode::process(ProcessContext& context)
// ?
break;
default:
- //cerr << "Ignored controller " << buffer[1] << endl;
+ //cerr << "Ignored controller " << buf[1] << endl;
break;
}
break;
default:
- fprintf(stderr, "Unknown (size %d) MIDI event %X\n", size, buffer[0]);
+ fprintf(stderr, "Unknown (size %d) MIDI event %X\n", size, buf[0]);
break;
}
} else {
- fprintf(stderr, "Unknown (size %d) MIDI event %X\n", size, buffer[0]);
+ fprintf(stderr, "Unknown (size %d) MIDI event %X\n", size, buf[0]);
}
if (midi_in->increment() == midi_in->this_nframes())
@@ -196,7 +196,7 @@ MidiNoteNode::note_on(uchar note_num, uchar velocity, FrameTime time, ProcessCon
uint32_t voice_num = 0;
if (key->state != Key::OFF) {
- cerr << "[MidiNoteNode] Double note. Who be sendin dem crazy midis?" << endl;
+ //cerr << "[MidiNoteNode] Double midi note received" << endl;
return;
}
diff --git a/src/libs/engine/MidiTriggerNode.cpp b/src/libs/engine/MidiTriggerNode.cpp
index 4d7ea000..0ae67c27 100644
--- a/src/libs/engine/MidiTriggerNode.cpp
+++ b/src/libs/engine/MidiTriggerNode.cpp
@@ -64,29 +64,28 @@ MidiTriggerNode::process(ProcessContext& context)
uint32_t subframes = 0;
uint16_t type = 0;
uint16_t size = 0;
- uint8_t* data = NULL;
+ uint8_t* buf = NULL;
EventBuffer* const midi_in = (EventBuffer*)_midi_in_port->buffer(0);
assert(midi_in->this_nframes() == context.nframes());
- while (midi_in->get_event(&frames, &subframes, &type, &size, &data) < context.nframes()) {
-
+ while (midi_in->get_event(&frames, &subframes, &type, &size, &buf)) {
const FrameTime time = context.start() + (FrameTime)frames;
if (size >= 3) {
- switch (data[0] & 0xF0) {
+ switch (buf[0] & 0xF0) {
case MIDI_CMD_NOTE_ON:
- if (data[2] == 0)
- note_off(data[1], time, context);
+ if (buf[2] == 0)
+ note_off(buf[1], time, context);
else
- note_on(data[1], data[2], time, context);
+ note_on(buf[1], buf[2], time, context);
break;
case MIDI_CMD_NOTE_OFF:
- note_off(data[1], time, context);
+ note_off(buf[1], time, context);
break;
case MIDI_CMD_CONTROL:
- if (data[1] == MIDI_CTL_ALL_NOTES_OFF
- || data[1] == MIDI_CTL_ALL_SOUNDS_OFF)
+ if (buf[1] == MIDI_CTL_ALL_NOTES_OFF
+ || buf[1] == MIDI_CTL_ALL_SOUNDS_OFF)
((AudioBuffer*)_gate_port->buffer(0))->set(0.0f, time);
default:
break;