diff options
-rw-r--r-- | src/common/interface/PortType.hpp | 3 | ||||
-rw-r--r-- | src/engine/AudioBuffer.cpp | 25 | ||||
-rw-r--r-- | src/engine/AudioBuffer.hpp | 29 | ||||
-rw-r--r-- | src/gui/PortMenu.cpp | 2 |
4 files changed, 25 insertions, 34 deletions
diff --git a/src/common/interface/PortType.hpp b/src/common/interface/PortType.hpp index 77211b71..72dbb327 100644 --- a/src/common/interface/PortType.hpp +++ b/src/common/interface/PortType.hpp @@ -79,9 +79,6 @@ private: case 1: return "lv2:AudioPort"; case 2: return "lv2:ControlPort"; case 3: return "lv2ev:EventPort"; - case 4: return "lv2ev:EventPort"; // MIDI (no longer used) - case 5: return "lv2ev:EventPort"; // OSC (no longer used) - case 6: return "sp:StringPort"; // String Port (no longer used) case 7: return "obj:ValuePort"; default: return ""; } diff --git a/src/engine/AudioBuffer.cpp b/src/engine/AudioBuffer.cpp index fbca1e7b..633a004b 100644 --- a/src/engine/AudioBuffer.cpp +++ b/src/engine/AudioBuffer.cpp @@ -39,7 +39,6 @@ using namespace Shared; AudioBuffer::AudioBuffer(Shared::PortType type, size_t size) : ObjectBuffer(size + sizeof(LV2_Object) + (type == PortType::AUDIO ? sizeof(LV2_Vector_Body) : 0)) - , _port_type(type) , _state(OK) , _set_value(0) , _set_time(0) @@ -75,7 +74,7 @@ AudioBuffer::AudioBuffer(Shared::PortType type, size_t size) void AudioBuffer::resize(size_t size) { - if (_port_type == PortType::AUDIO) { + if (_type == PortType::AUDIO) { ObjectBuffer::resize(size + sizeof(LV2_Vector_Body)); vector()->elem_count = size / sizeof(Sample); } @@ -103,7 +102,7 @@ AudioBuffer::clear() void AudioBuffer::set_value(Sample val, FrameTime cycle_start, FrameTime time) { - if (_port_type == PortType::CONTROL) + if (is_control()) time = cycle_start; const FrameTime offset = time - cycle_start; @@ -163,10 +162,19 @@ AudioBuffer::copy(const Sample* src, size_t start_sample, size_t end_sample) void AudioBuffer::copy(Context& context, const Buffer* src) { - if (_type == src->type()) { + const AudioBuffer* src_abuf = dynamic_cast<const AudioBuffer*>(src); + if (!src_abuf) { + clear(); + return; + } + + // Control => Control or Audio => Audio + if (src_abuf->is_control() == is_control()) { ObjectBuffer::copy(context, src); - } else if (_type == PortType::AUDIO && src->type() == PortType::CONTROL) { - set_block(((AudioBuffer*)src)->data()[0], 0, nframes()); + + // Control => Audio or Audio => Control + } else { + set_block(src_abuf->data()[0], 0, nframes()); } } @@ -179,11 +187,10 @@ AudioBuffer::copy(Context& context, const Buffer* src) void AudioBuffer::mix(Context& context, const Buffer* const src) { - if (src->type() != PortType::CONTROL && src->type() != PortType::AUDIO) + const AudioBuffer* src_abuf = dynamic_cast<const AudioBuffer*>(src); + if (!src_abuf) return; - AudioBuffer* src_abuf = (AudioBuffer*)src; - Sample* const buf = data(); const Sample* const src_buf = src_abuf->data(); diff --git a/src/engine/AudioBuffer.hpp b/src/engine/AudioBuffer.hpp index 25cfd15c..f7d036ff 100644 --- a/src/engine/AudioBuffer.hpp +++ b/src/engine/AudioBuffer.hpp @@ -43,30 +43,18 @@ public: void copy(Context& context, const Buffer* src); void mix(Context& context, const Buffer* src); + bool is_control() const { return _type.symbol() == Shared::PortType::CONTROL; } + inline Sample* data() const { - switch (_port_type.symbol()) { - case Shared::PortType::CONTROL: - return (Sample*)object()->body; - case Shared::PortType::AUDIO: - return (Sample*)(object()->body + sizeof(LV2_Vector_Body)); - default: - return NULL; - } + return (is_control()) + ? (Sample*)object()->body + : (Sample*)(object()->body + sizeof(LV2_Vector_Body)); } inline SampleCount nframes() const { - SampleCount ret = 0; - switch (_port_type.symbol()) { - case Shared::PortType::CONTROL: - ret = 1; - break; - case Shared::PortType::AUDIO: - ret = (_size - sizeof(LV2_Object) - sizeof(LV2_Vector_Body)) / sizeof(Sample); - break; - default: - ret = 0; - } - return ret; + return (is_control()) + ? 1 + : (_size - sizeof(LV2_Object) - sizeof(LV2_Vector_Body)) / sizeof(Sample); } inline Sample& value_at(size_t offset) const @@ -82,7 +70,6 @@ private: LV2_Vector_Body* vector() { return(LV2_Vector_Body*)object()->body; } - Shared::PortType _port_type; ///< Type of port this buffer is for State _state; ///< State of buffer for setting values next cycle Sample _set_value; ///< Value set by set_value (for completing the set next cycle) FrameTime _set_time; ///< Time _set_value was set (to reset next cycle) diff --git a/src/gui/PortMenu.cpp b/src/gui/PortMenu.cpp index bbf5cbbd..48a0e2c3 100644 --- a/src/gui/PortMenu.cpp +++ b/src/gui/PortMenu.cpp @@ -48,7 +48,7 @@ PortMenu::init(SharedPtr<PortModel> port, bool patch_port) _destroy_menuitem->hide(); } - if (port->type() == PortType::EVENTS || port->type() == PortType::VALUE) + if (port->type() == PortType::EVENTS) _polyphonic_menuitem->hide(); _enable_signal = true; |