diff options
Diffstat (limited to 'src/libs')
-rw-r--r-- | src/libs/engine/AudioBuffer.cpp | 32 | ||||
-rw-r--r-- | src/libs/engine/AudioBuffer.hpp | 9 | ||||
-rw-r--r-- | src/libs/engine/Buffer.hpp | 4 | ||||
-rw-r--r-- | src/libs/engine/ConnectionImpl.cpp | 4 | ||||
-rw-r--r-- | src/libs/engine/DuplexPort.cpp | 4 | ||||
-rw-r--r-- | src/libs/engine/EventBuffer.cpp | 4 | ||||
-rw-r--r-- | src/libs/engine/EventBuffer.hpp | 4 | ||||
-rw-r--r-- | src/libs/engine/InputPort.cpp | 6 | ||||
-rw-r--r-- | src/libs/engine/JackMidiDriver.cpp | 4 | ||||
-rw-r--r-- | src/libs/engine/LADSPANode.cpp | 2 | ||||
-rw-r--r-- | src/libs/engine/LV2Node.cpp | 6 | ||||
-rw-r--r-- | src/libs/engine/MidiControlNode.cpp | 12 | ||||
-rw-r--r-- | src/libs/engine/MidiControlNode.hpp | 2 | ||||
-rw-r--r-- | src/libs/engine/MidiNoteNode.cpp | 54 | ||||
-rw-r--r-- | src/libs/engine/MidiNoteNode.hpp | 12 | ||||
-rw-r--r-- | src/libs/engine/MidiTriggerNode.cpp | 29 | ||||
-rw-r--r-- | src/libs/engine/MidiTriggerNode.hpp | 4 | ||||
-rw-r--r-- | src/libs/engine/OutputPort.cpp | 4 | ||||
-rw-r--r-- | src/libs/engine/events/NoteEvent.cpp | 8 | ||||
-rw-r--r-- | src/libs/engine/events/SetPortValueEvent.cpp | 8 |
20 files changed, 101 insertions, 111 deletions
diff --git a/src/libs/engine/AudioBuffer.cpp b/src/libs/engine/AudioBuffer.cpp index b4038586..b874d527 100644 --- a/src/libs/engine/AudioBuffer.cpp +++ b/src/libs/engine/AudioBuffer.cpp @@ -36,6 +36,7 @@ AudioBuffer::AudioBuffer(size_t size) , _filled_size(0) , _state(OK) , _set_value(0) + , _set_time(0) { assert(_size > 0); allocate(); @@ -68,7 +69,7 @@ AudioBuffer::resize(size_t size) else _data = old_data; - set(0, 0, _size-1); + set_block(0, 0, _size-1); } @@ -92,7 +93,7 @@ AudioBuffer::allocate() _data = _local_data; - set(0, 0, _size-1); + set_block(0, 0, _size-1); } @@ -113,7 +114,7 @@ AudioBuffer::deallocate() void AudioBuffer::clear() { - set(0, 0, _size-1); + set_block(0, 0, _size-1); _state = OK; _filled_size = 0; } @@ -126,15 +127,17 @@ AudioBuffer::clear() * long as pre_process() is called every cycle. */ void -AudioBuffer::set(Sample val, size_t start_sample) +AudioBuffer::set_value(Sample val, FrameTime cycle_start, FrameTime time) { - assert(start_sample < _size); + FrameTime offset = time - cycle_start; + assert(offset < _size); - set(val, start_sample, _size-1); + set_block(val, offset, _size - 1); - if (start_sample > 0) + if (offset > 0) _state = HALF_SET_CYCLE_1; + _set_time = time; _set_value = val; } @@ -144,15 +147,15 @@ AudioBuffer::set(Sample val, size_t start_sample) * @a start_sample and @a end_sample define the inclusive range to be set. */ void -AudioBuffer::set(Sample val, size_t start_sample, size_t end_sample) +AudioBuffer::set_block(Sample val, size_t start_offset, size_t end_offset) { - assert(end_sample >= start_sample); - assert(end_sample < _size); + assert(end_offset >= start_offset); + assert(end_offset < _size); Sample* const buf = data(); assert(buf); - for (size_t i=start_sample; i <= end_sample; ++i) + for (size_t i = start_offset; i <= end_offset; ++i) buf[i] = val; } @@ -254,7 +257,7 @@ AudioBuffer::unjoin() void -AudioBuffer::prepare_read(SampleCount nframes) +AudioBuffer::prepare_read(FrameTime start, SampleCount nframes) { // FIXME: nframes parameter doesn't actually work, // writing starts from 0 every time @@ -262,10 +265,11 @@ AudioBuffer::prepare_read(SampleCount nframes) switch (_state) { case HALF_SET_CYCLE_1: - _state = HALF_SET_CYCLE_2; + if (start > _set_time) + _state = HALF_SET_CYCLE_2; break; case HALF_SET_CYCLE_2: - set(_set_value, 0, _size-1); + set_block(_set_value, 0, _size-1); _state = OK; break; default: diff --git a/src/libs/engine/AudioBuffer.hpp b/src/libs/engine/AudioBuffer.hpp index 44650856..513c188f 100644 --- a/src/libs/engine/AudioBuffer.hpp +++ b/src/libs/engine/AudioBuffer.hpp @@ -33,8 +33,8 @@ public: AudioBuffer(size_t capacity); void clear(); - void set(Sample val, size_t start_sample); - void set(Sample val, size_t start_sample, size_t end_sample); + void set_value(Sample val, FrameTime cycle_start, FrameTime time); + void set_block(Sample val, size_t start_offset, size_t end_offset); void scale(Sample val, size_t start_sample, size_t end_sample); void copy(const Buffer* src, size_t start_sample, size_t end_sample); void accumulate(const AudioBuffer* src, size_t start_sample, size_t end_sample); @@ -53,8 +53,8 @@ public: inline Sample& value_at(size_t offset) const { assert(offset < _size); return data()[offset]; } - void prepare_read(SampleCount nframes); - void prepare_write(SampleCount nframes) {} + void prepare_read(FrameTime start, SampleCount nframes); + void prepare_write(FrameTime start, SampleCount nframes) {} void rewind() const {} void resize(size_t size); @@ -75,6 +75,7 @@ private: size_t _filled_size; ///< Usable buffer size (for MIDI ports etc) State _state; ///< State of buffer for setting values next cycle Sample _set_value; ///< Value set by @ref set (may need to be set next cycle) + FrameTime _set_time; ///< Time _set_value was set (to reset next cycle) }; diff --git a/src/libs/engine/Buffer.hpp b/src/libs/engine/Buffer.hpp index 30180064..3e3f7563 100644 --- a/src/libs/engine/Buffer.hpp +++ b/src/libs/engine/Buffer.hpp @@ -46,8 +46,8 @@ public: /** Rewing (ie reset read pointer), but leave contents unchanged */ virtual void rewind() const = 0; - virtual void prepare_read(SampleCount nframes) = 0; - virtual void prepare_write(SampleCount nframes) = 0; + virtual void prepare_read(FrameTime start, SampleCount nframes) = 0; + virtual void prepare_write(FrameTime start, SampleCount nframes) = 0; bool is_joined() const { return (_joined_buf != NULL); } Buffer* joined_buffer() const { return _joined_buf; } diff --git a/src/libs/engine/ConnectionImpl.cpp b/src/libs/engine/ConnectionImpl.cpp index 63f2028c..07884336 100644 --- a/src/libs/engine/ConnectionImpl.cpp +++ b/src/libs/engine/ConnectionImpl.cpp @@ -146,7 +146,7 @@ ConnectionImpl::process(ProcessContext& context) // Write last value of src buffer to remainder of dst buffer, if necessary if (copy_size < mix_buf->size()) - mix_buf->set(src_buffer->value_at(copy_size-1), copy_size, mix_buf->size()-1); + mix_buf->set_block(src_buffer->value_at(copy_size-1), copy_size, mix_buf->size()-1); // Accumulate the source's voices into local buffer starting at the second // voice (buffer is already set to first voice above) @@ -160,7 +160,7 @@ ConnectionImpl::process(ProcessContext& context) for (uint32_t j=1; j < src_port()->poly(); ++j) src_value += ((AudioBuffer*)src_port()->buffer(j))->value_at(copy_size-1); - mix_buf->set(src_value, copy_size, mix_buf->size()-1); + mix_buf->set_block(src_value, copy_size, mix_buf->size()-1); } // Scale the buffer down. diff --git a/src/libs/engine/DuplexPort.cpp b/src/libs/engine/DuplexPort.cpp index 71a65e4f..31bfbe09 100644 --- a/src/libs/engine/DuplexPort.cpp +++ b/src/libs/engine/DuplexPort.cpp @@ -61,12 +61,12 @@ DuplexPort::pre_process(ProcessContext& context) for (uint32_t i=0; i < _poly; ++i) if (!_buffers->at(i)->is_joined()) - _buffers->at(i)->prepare_write(context.nframes()); + _buffers->at(i)->prepare_write(context.start(), context.nframes()); } else { for (uint32_t i=0; i < _poly; ++i) - _buffers->at(i)->prepare_read(context.nframes()); + _buffers->at(i)->prepare_read(context.start(), context.nframes()); broadcast(context); } diff --git a/src/libs/engine/EventBuffer.cpp b/src/libs/engine/EventBuffer.cpp index dfeff610..73722ee9 100644 --- a/src/libs/engine/EventBuffer.cpp +++ b/src/libs/engine/EventBuffer.cpp @@ -100,7 +100,7 @@ EventBuffer::unjoin() void -EventBuffer::prepare_read(SampleCount nframes) +EventBuffer::prepare_read(FrameTime start, SampleCount nframes) { //cerr << "\t" << this << " prepare_read: " << event_count() << endl; rewind(); @@ -109,7 +109,7 @@ EventBuffer::prepare_read(SampleCount nframes) void -EventBuffer::prepare_write(SampleCount nframes) +EventBuffer::prepare_write(FrameTime start, SampleCount nframes) { //cerr << "\t" << this << " prepare_write: " << event_count() << endl; reset(nframes); diff --git a/src/libs/engine/EventBuffer.hpp b/src/libs/engine/EventBuffer.hpp index 20fde057..0c80d452 100644 --- a/src/libs/engine/EventBuffer.hpp +++ b/src/libs/engine/EventBuffer.hpp @@ -33,8 +33,8 @@ public: ~EventBuffer(); - void prepare_read(SampleCount nframes); - void prepare_write(SampleCount nframes); + void prepare_read(FrameTime start, SampleCount nframes); + void prepare_write(FrameTime start, SampleCount nframes); bool join(Buffer* buf); void unjoin(); diff --git a/src/libs/engine/InputPort.cpp b/src/libs/engine/InputPort.cpp index 052ccde0..8aa73e2c 100644 --- a/src/libs/engine/InputPort.cpp +++ b/src/libs/engine/InputPort.cpp @@ -164,7 +164,7 @@ InputPort::pre_process(ProcessContext& context) if (_connections.size() == 0) { for (uint32_t i=0; i < _poly; ++i) - buffer(i)->prepare_read(context.nframes()); + buffer(i)->prepare_read(context.start(), context.nframes()); return; } @@ -186,7 +186,7 @@ InputPort::pre_process(ProcessContext& context) } for (uint32_t i=0; i < _poly; ++i) - buffer(i)->prepare_read(context.nframes()); + buffer(i)->prepare_read(context.start(), context.nframes()); /*cerr << path() << " poly = " << _poly << ", mixdown: " << do_mixdown << ", fixed buffers: " << _fixed_buffers << ", joined: " << _buffers->at(0)->is_joined() @@ -243,7 +243,7 @@ InputPort::post_process(ProcessContext& context) // Prepare for next cycle for (uint32_t i=0; i < _poly; ++i) - buffer(i)->prepare_write(context.nframes()); + buffer(i)->prepare_write(context.start(), context.nframes()); _set_by_user = false; diff --git a/src/libs/engine/JackMidiDriver.cpp b/src/libs/engine/JackMidiDriver.cpp index 7aba309a..c20bed8b 100644 --- a/src/libs/engine/JackMidiDriver.cpp +++ b/src/libs/engine/JackMidiDriver.cpp @@ -85,7 +85,7 @@ JackMidiPort::pre_process(ProcessContext& context) void* jack_buffer = jack_port_get_buffer(_jack_port, context.nframes()); const jack_nframes_t event_count = jack_midi_get_event_count(jack_buffer); - patch_buf->prepare_write(context.nframes()); + patch_buf->prepare_write(context.start(), context.nframes()); // Copy events from Jack port buffer into patch port buffer for (jack_nframes_t i=0; i < event_count; ++i) { @@ -120,7 +120,7 @@ JackMidiPort::post_process(ProcessContext& context) assert(_patch_port->poly() == 1); assert(patch_buf); - patch_buf->prepare_read(context.nframes()); + patch_buf->prepare_read(context.start(), context.nframes()); jack_midi_clear_buffer(jack_buf); uint32_t frames = 0; diff --git a/src/libs/engine/LADSPANode.cpp b/src/libs/engine/LADSPANode.cpp index ef4b0ece..38436046 100644 --- a/src/libs/engine/LADSPANode.cpp +++ b/src/libs/engine/LADSPANode.cpp @@ -221,7 +221,7 @@ LADSPANode::instantiate() // Set initial/default value if (port->buffer_size() == 1) { for (uint32_t i=0; i < _polyphony; ++i) - ((AudioBuffer*)port->buffer(i))->set(value, 0); + ((AudioBuffer*)port->buffer(i))->set_value(value, 0, 0); } if (port->is_input() && port->buffer_size() == 1) { diff --git a/src/libs/engine/LV2Node.cpp b/src/libs/engine/LV2Node.cpp index bd4c2737..de1e61ca 100644 --- a/src/libs/engine/LV2Node.cpp +++ b/src/libs/engine/LV2Node.cpp @@ -200,7 +200,7 @@ LV2Node::instantiate() port = new OutputPort(this, port_name, j, _polyphony, data_type, defatm, port_buffer_size); if (direction == INPUT && data_type == DataType::CONTROL) - ((AudioBuffer*)port->buffer(0))->set(def, 0); + ((AudioBuffer*)port->buffer(0))->set_value(def, 0, 0); _ports->at(j) = port; } @@ -223,9 +223,9 @@ LV2Node::activate() set_port_buffer(i, j, port->buffer(i)); if (port->type() == DataType::CONTROL) { - ((AudioBuffer*)port->buffer(i))->set(port->value().get_float(), 0); + ((AudioBuffer*)port->buffer(i))->set_value(port->value().get_float(), 0, 0); } else if (port->type() == DataType::AUDIO) { - ((AudioBuffer*)port->buffer(i))->set(0.0f, 0); + ((AudioBuffer*)port->buffer(i))->set_value(0.0f, 0, 0); } } slv2_instance_activate((*_instances)[i]); diff --git a/src/libs/engine/MidiControlNode.cpp b/src/libs/engine/MidiControlNode.cpp index afd588ea..c855f307 100644 --- a/src/libs/engine/MidiControlNode.cpp +++ b/src/libs/engine/MidiControlNode.cpp @@ -83,7 +83,7 @@ MidiControlNode::process(ProcessContext& context) while (midi_in->get_event(&frames, &subframes, &type, &size, &buf)) { // FIXME: type if (size >= 3 && (buf[0] & 0xF0) == MIDI_CMD_CONTROL) - control(buf[1], buf[2], (SampleCount)frames); + control(context, buf[1], buf[2], frames + context.start()); midi_in->increment(); } @@ -93,9 +93,9 @@ MidiControlNode::process(ProcessContext& context) void -MidiControlNode::control(uchar control_num, uchar val, SampleCount offset) +MidiControlNode::control(ProcessContext& context, uchar control_num, uchar val, FrameTime time) { - assert(offset < _buffer_size); + assert(time - context.start() < _buffer_size); Sample scaled_value; @@ -125,15 +125,15 @@ MidiControlNode::control(uchar control_num, uchar val, SampleCount offset) Sample log_offset = 0; if (min_port_val < 0) log_offset = fabs(min_port_val); - const Sample min = log(min_port_val+1+log_offset); - const Sample max = log(max_port_val+1+log_offset); + const Sample min = log(min_port_val + 1 + log_offset); + const Sample max = log(max_port_val + 1 + log_offset); scaled_value = expf(nval * (max - min) + min) - 1 - log_offset; } else { scaled_value = ((nval) * (max_port_val - min_port_val)) + min_port_val; } if (control_num == ((AudioBuffer*)_param_port->buffer(0))->value_at(0)) - ((AudioBuffer*)_audio_port->buffer(0))->set(scaled_value, offset); + ((AudioBuffer*)_audio_port->buffer(0))->set_value(scaled_value, context.start(), time); } diff --git a/src/libs/engine/MidiControlNode.hpp b/src/libs/engine/MidiControlNode.hpp index 1df42b33..2f0496a3 100644 --- a/src/libs/engine/MidiControlNode.hpp +++ b/src/libs/engine/MidiControlNode.hpp @@ -42,7 +42,7 @@ public: void process(ProcessContext& context); - void control(uchar control_num, uchar val, SampleCount offset); + void control(ProcessContext& context, uchar control_num, uchar val, FrameTime time); void learn(MidiLearnResponseEvent* ev) { _learning = true; _learn_event = ev; } diff --git a/src/libs/engine/MidiNoteNode.cpp b/src/libs/engine/MidiNoteNode.cpp index 3c4f0e56..53778f17 100644 --- a/src/libs/engine/MidiNoteNode.cpp +++ b/src/libs/engine/MidiNoteNode.cpp @@ -141,24 +141,24 @@ MidiNoteNode::process(ProcessContext& context) switch (buf[0] & 0xF0) { case MIDI_CMD_NOTE_ON: if (buf[2] == 0) - note_off(buf[1], time, context); + note_off(context, buf[1], time); else - note_on(buf[1], buf[2], time, context); + note_on(context, buf[1], buf[2], time); break; case MIDI_CMD_NOTE_OFF: - note_off(buf[1], time, context); + note_off(context, buf[1], time); break; case MIDI_CMD_CONTROL: switch (buf[1]) { case MIDI_CTL_ALL_NOTES_OFF: case MIDI_CTL_ALL_SOUNDS_OFF: - all_notes_off(time, context); + all_notes_off(context, time); break; case MIDI_CTL_SUSTAIN: if (buf[2] > 63) - sustain_on(time, context); + sustain_on(context, time); else - sustain_off(time, context); + sustain_off(context, time); break; case MIDI_CMD_BENDER: // ? @@ -185,7 +185,7 @@ MidiNoteNode::process(ProcessContext& context) void -MidiNoteNode::note_on(uchar note_num, uchar velocity, FrameTime time, ProcessContext& context) +MidiNoteNode::note_on(ProcessContext& context, uchar note_num, uchar velocity, FrameTime time) { assert(time >= context.start() && time <= context.end()); assert(time - context.start() < _buffer_size); @@ -249,21 +249,13 @@ MidiNoteNode::note_on(uchar note_num, uchar velocity, FrameTime time, ProcessCon assert(_keys[voice->note].state == Key::Key::ON_ASSIGNED); assert(_keys[voice->note].voice == voice_num); - // FIXME FIXME FIXME - - SampleCount offset = time - context.start(); - - // one-sample jitter hack to avoid having to deal with trigger sample "next time" - if (offset == (SampleCount)(_buffer_size-1)) - --offset; - - ((AudioBuffer*)_freq_port->buffer(voice_num))->set(note_to_freq(note_num), offset); - ((AudioBuffer*)_vel_port->buffer(voice_num))->set(velocity/127.0, offset); - ((AudioBuffer*)_gate_port->buffer(voice_num))->set(1.0f, offset); + ((AudioBuffer*)_freq_port->buffer(voice_num))->set_value(note_to_freq(note_num), context.start(), time); + ((AudioBuffer*)_vel_port->buffer(voice_num))->set_value(velocity/127.0, context.start(), time); + ((AudioBuffer*)_gate_port->buffer(voice_num))->set_value(1.0f, context.start(), time); // trigger (one sample) - ((AudioBuffer*)_trig_port->buffer(voice_num))->set(1.0f, offset, offset); - ((AudioBuffer*)_trig_port->buffer(voice_num))->set(0.0f, offset+1); + ((AudioBuffer*)_trig_port->buffer(voice_num))->set_value(1.0f, context.start(), time); + ((AudioBuffer*)_trig_port->buffer(voice_num))->set_value(0.0f, context.start(), time + 1); assert(key->state == Key::Key::ON_ASSIGNED); assert(voice->state == Voice::Voice::ACTIVE); @@ -273,7 +265,7 @@ MidiNoteNode::note_on(uchar note_num, uchar velocity, FrameTime time, ProcessCon void -MidiNoteNode::note_off(uchar note_num, FrameTime time, ProcessContext& context) +MidiNoteNode::note_off(ProcessContext& context, uchar note_num, FrameTime time) { assert(time >= context.start() && time <= context.end()); assert(time - context.start() < _buffer_size); @@ -289,7 +281,7 @@ MidiNoteNode::note_off(uchar note_num, FrameTime time, ProcessContext& context) if ( ! _sustain) { //cerr << "... free voice " << key->voice << endl; - free_voice(key->voice, time, context); + free_voice(context, key->voice, time); } else { //cerr << "... hold voice " << key->voice << endl; (*_voices)[key->voice].state = Voice::HOLDING; @@ -307,7 +299,7 @@ MidiNoteNode::note_off(uchar note_num, FrameTime time, ProcessContext& context) void -MidiNoteNode::free_voice(uint32_t voice, FrameTime time, ProcessContext& context) +MidiNoteNode::free_voice(ProcessContext& context, uint32_t voice, FrameTime time) { assert(time >= context.start() && time <= context.end()); assert(time - context.start() < _buffer_size); @@ -330,7 +322,7 @@ MidiNoteNode::free_voice(uint32_t voice, FrameTime time, ProcessContext& context assert(replace_key->state == Key::ON_UNASSIGNED); // Change the freq but leave the gate high and don't retrigger - ((AudioBuffer*)_freq_port->buffer(voice))->set(note_to_freq(replace_key_num), time - context.start()); + ((AudioBuffer*)_freq_port->buffer(voice))->set_value(note_to_freq(replace_key_num), context.start(), time); replace_key->state = Key::ON_ASSIGNED; replace_key->voice = voice; @@ -340,14 +332,14 @@ MidiNoteNode::free_voice(uint32_t voice, FrameTime time, ProcessContext& context } else { // No new note for voice, deactivate (set gate low) //cerr << "[MidiNoteNode] Note off. Key " << (int)note_num << ", Voice " << voice << " Killed" << endl; - ((AudioBuffer*)_gate_port->buffer(voice))->set(0.0f, time - context.start()); + ((AudioBuffer*)_gate_port->buffer(voice))->set_value(0.0f, context.start(), time); (*_voices)[voice].state = Voice::FREE; } } void -MidiNoteNode::all_notes_off(FrameTime time, ProcessContext& context) +MidiNoteNode::all_notes_off(ProcessContext& context, FrameTime time) { assert(time >= context.start() && time <= context.end()); assert(time - context.start() < _buffer_size); @@ -356,8 +348,8 @@ MidiNoteNode::all_notes_off(FrameTime time, ProcessContext& context) // FIXME: set all keys to Key::OFF? - for (uint32_t i=0; i < _polyphony; ++i) { - ((AudioBuffer*)_gate_port->buffer(i))->set(0.0f, time - context.start()); + for (uint32_t i = 0; i < _polyphony; ++i) { + ((AudioBuffer*)_gate_port->buffer(i))->set_value(0.0f, context.start(), time); (*_voices)[i].state = Voice::FREE; } } @@ -374,14 +366,14 @@ MidiNoteNode::note_to_freq(int num) void -MidiNoteNode::sustain_on(FrameTime time, ProcessContext& context) +MidiNoteNode::sustain_on(ProcessContext& context, FrameTime time) { _sustain = true; } void -MidiNoteNode::sustain_off(FrameTime time, ProcessContext& context) +MidiNoteNode::sustain_off(ProcessContext& context, FrameTime time) { assert(time >= context.start() && time <= context.end()); assert(time - context.start() < _buffer_size); @@ -390,7 +382,7 @@ MidiNoteNode::sustain_off(FrameTime time, ProcessContext& context) for (uint32_t i=0; i < _polyphony; ++i) if ((*_voices)[i].state == Voice::HOLDING) - free_voice(i, time, context); + free_voice(context, i, time); } diff --git a/src/libs/engine/MidiNoteNode.hpp b/src/libs/engine/MidiNoteNode.hpp index e7e04acd..eebcbda6 100644 --- a/src/libs/engine/MidiNoteNode.hpp +++ b/src/libs/engine/MidiNoteNode.hpp @@ -45,12 +45,12 @@ public: void process(ProcessContext& context); - void note_on(uchar note_num, uchar velocity, FrameTime time, ProcessContext& context); - void note_off(uchar note_num, FrameTime time, ProcessContext& context); - void all_notes_off(FrameTime time, ProcessContext& context); + void note_on(ProcessContext& context, uchar note_num, uchar velocity, FrameTime time); + void note_off(ProcessContext& context, uchar note_num, FrameTime time); + void all_notes_off(ProcessContext& context, FrameTime time); - void sustain_on(FrameTime time, ProcessContext& context); - void sustain_off(FrameTime time, ProcessContext& context); + void sustain_on(ProcessContext& context, FrameTime time); + void sustain_off(ProcessContext& context, FrameTime time); private: /** Key, one for each key on the keyboard */ @@ -68,7 +68,7 @@ private: }; float note_to_freq(int num); - void free_voice(uint32_t voice, FrameTime time, ProcessContext& context); + void free_voice(ProcessContext& context, uint32_t voice, FrameTime time); Raul::Array<Voice>* _voices; Raul::Array<Voice>* _prepared_voices; diff --git a/src/libs/engine/MidiTriggerNode.cpp b/src/libs/engine/MidiTriggerNode.cpp index 5fa1cd4b..7b210201 100644 --- a/src/libs/engine/MidiTriggerNode.cpp +++ b/src/libs/engine/MidiTriggerNode.cpp @@ -78,17 +78,17 @@ MidiTriggerNode::process(ProcessContext& context) switch (buf[0] & 0xF0) { case MIDI_CMD_NOTE_ON: if (buf[2] == 0) - note_off(buf[1], time, context); + note_off(context, buf[1], time); else - note_on(buf[1], buf[2], time, context); + note_on(context, buf[1], buf[2], time); break; case MIDI_CMD_NOTE_OFF: - note_off(buf[1], time, context); + note_off(context, buf[1], time); break; case MIDI_CMD_CONTROL: if (buf[1] == MIDI_CTL_ALL_NOTES_OFF || buf[1] == MIDI_CTL_ALL_SOUNDS_OFF) - ((AudioBuffer*)_gate_port->buffer(0))->set(0.0f, time); + ((AudioBuffer*)_gate_port->buffer(0))->set_value(0.0f, context.start(), time); default: break; } @@ -102,7 +102,7 @@ MidiTriggerNode::process(ProcessContext& context) void -MidiTriggerNode::note_on(uchar note_num, uchar velocity, FrameTime time, ProcessContext& context) +MidiTriggerNode::note_on(ProcessContext& context, uchar note_num, uchar velocity, FrameTime time) { assert(time >= context.start() && time <= context.end()); assert(time - context.start() < _buffer_size); @@ -115,29 +115,24 @@ MidiTriggerNode::note_on(uchar note_num, uchar velocity, FrameTime time, Process cerr << "!\n"; - // FIXME FIXME FIXME - SampleCount offset = time - context.start(); - - // See comments in MidiNoteNode::note_on (FIXME) - if (offset == (SampleCount)(_buffer_size-1)) - --offset; + ((AudioBuffer*)_gate_port->buffer(0))->set_value(1.0f, context.start(), time); + ((AudioBuffer*)_trig_port->buffer(0))->set_value(1.0f, context.start(), time); + ((AudioBuffer*)_trig_port->buffer(0))->set_value(0.0f, context.start(), time + 1); + ((AudioBuffer*)_vel_port->buffer(0))->set_value(velocity / 127.0f, context.start(), time); - ((AudioBuffer*)_gate_port->buffer(0))->set(1.0f, offset); - ((AudioBuffer*)_trig_port->buffer(0))->set(1.0f, offset, offset); - ((AudioBuffer*)_trig_port->buffer(0))->set(0.0f, offset+1); - ((AudioBuffer*)_vel_port->buffer(0))->set(velocity/127.0f, offset); + assert(((AudioBuffer*)_trig_port->buffer(0))->data()[time - context.start()] == 1.0f); } } void -MidiTriggerNode::note_off(uchar note_num, FrameTime time, ProcessContext& context) +MidiTriggerNode::note_off(ProcessContext& context, uchar note_num, FrameTime time) { assert(time >= context.start() && time <= context.end()); assert(time - context.start() < _buffer_size); if (note_num == lrintf(((AudioBuffer*)_note_port->buffer(0))->value_at(0))) - ((AudioBuffer*)_gate_port->buffer(0))->set(0.0f, time - context.start()); + ((AudioBuffer*)_gate_port->buffer(0))->set_value(0.0f, context.start(), time); } diff --git a/src/libs/engine/MidiTriggerNode.hpp b/src/libs/engine/MidiTriggerNode.hpp index cebb64fe..ba96589b 100644 --- a/src/libs/engine/MidiTriggerNode.hpp +++ b/src/libs/engine/MidiTriggerNode.hpp @@ -44,8 +44,8 @@ public: void process(ProcessContext& context); - void note_on(uchar note_num, uchar velocity, FrameTime time, ProcessContext& context); - void note_off(uchar note_num, FrameTime time, ProcessContext& context); + void note_on(ProcessContext& context, uchar note_num, uchar velocity, FrameTime time); + void note_off(ProcessContext& context, uchar note_num, FrameTime time); private: InputPort* _midi_in_port; diff --git a/src/libs/engine/OutputPort.cpp b/src/libs/engine/OutputPort.cpp index 6f36a34a..116d9a3e 100644 --- a/src/libs/engine/OutputPort.cpp +++ b/src/libs/engine/OutputPort.cpp @@ -43,7 +43,7 @@ void OutputPort::pre_process(ProcessContext& context) { for (uint32_t i=0; i < _poly; ++i) - buffer(i)->prepare_write(context.nframes()); + buffer(i)->prepare_write(context.start(), context.nframes()); } @@ -51,7 +51,7 @@ void OutputPort::post_process(ProcessContext& context) { for (uint32_t i=0; i < _poly; ++i) - buffer(i)->prepare_read(context.nframes()); + buffer(i)->prepare_read(context.start(), context.nframes()); //cerr << path() << " output post: buffer: " << buffer(0) << endl; diff --git a/src/libs/engine/events/NoteEvent.cpp b/src/libs/engine/events/NoteEvent.cpp index ff96e94c..8f262d14 100644 --- a/src/libs/engine/events/NoteEvent.cpp +++ b/src/libs/engine/events/NoteEvent.cpp @@ -72,14 +72,14 @@ NoteEvent::execute(ProcessContext& context) if (_node != NULL && _node->plugin()->type() == Plugin::Internal) { if (_on) { if (_node->plugin_impl()->uri() == "ingen:note_node") - ((MidiNoteNode*)_node)->note_on(_note_num, _velocity, _time, context); + ((MidiNoteNode*)_node)->note_on(context, _note_num, _velocity, _time); else if (_node->plugin_impl()->uri() == "ingen:trigger_node") - ((MidiTriggerNode*)_node)->note_on(_note_num, _velocity, _time, context); + ((MidiTriggerNode*)_node)->note_on(context, _note_num, _velocity, _time); } else { if (_node->plugin_impl()->uri() == "ingen:note_node") - ((MidiNoteNode*)_node)->note_off(_note_num, _time, context); + ((MidiNoteNode*)_node)->note_off(context, _note_num, _time); else if (_node->plugin_impl()->uri() == "ingen:trigger_node") - ((MidiTriggerNode*)_node)->note_off(_note_num, _time, context); + ((MidiTriggerNode*)_node)->note_off(context, _note_num, _time); } } } diff --git a/src/libs/engine/events/SetPortValueEvent.cpp b/src/libs/engine/events/SetPortValueEvent.cpp index cf4ce6fd..267db836 100644 --- a/src/libs/engine/events/SetPortValueEvent.cpp +++ b/src/libs/engine/events/SetPortValueEvent.cpp @@ -125,13 +125,11 @@ SetPortValueEvent::execute(ProcessContext& context) Buffer* const buf = _port->buffer(0); AudioBuffer* const abuf = dynamic_cast<AudioBuffer*>(buf); if (abuf) { - const uint32_t offset = (buf->size() == 1) ? 0 : _time - context.start(); - if (_omni) for (uint32_t i=0; i < _port->poly(); ++i) - ((AudioBuffer*)_port->buffer(i))->set(*(float*)_data, offset); + ((AudioBuffer*)_port->buffer(i))->set_value(*(float*)_data, context.start(), _time); else - ((AudioBuffer*)_port->buffer(_voice_num))->set(*(float*)_data, offset); + ((AudioBuffer*)_port->buffer(_voice_num))->set_value(*(float*)_data, context.start(), _time); return; } @@ -143,7 +141,7 @@ SetPortValueEvent::execute(ProcessContext& context) LV2URIMap* map = (LV2URIMap*)f->controller; const uint32_t type_id = map->uri_to_id(NULL, "http://lv2plug.in/ns/ext/midi#MidiEvent"); const uint32_t frames = std::max((uint32_t)(_time - context.start()), ebuf->latest_frames()); - ebuf->prepare_write(context.nframes()); + ebuf->prepare_write(context.start(), context.nframes()); // FIXME: how should this work? binary over OSC, ick // Message is an event: ebuf->append(frames, 0, type_id, _data_size, (const unsigned char*)_data); |