From 780665a17bffa3665d3b454c6f4cedc0500c992e Mon Sep 17 00:00:00 2001 From: jean-millot Date: Tue, 15 Nov 2016 18:01:17 +0100 Subject: [PATCH 1/2] Taking arguments into acount for dac~ --- Client/Source/KiwiApp_DspDeviceManager.cpp | 10 ++---- Client/Source/KiwiApp_DspDeviceManager.hpp | 2 +- Client/Source/KiwiApp_PatcherView.cpp | 2 +- .../KiwiEngine/KiwiEngine_AudioControler.hpp | 2 +- Modules/KiwiEngine/KiwiEngine_Objects.cpp | 32 ++++++++++++++++++- Modules/KiwiEngine/KiwiEngine_Objects.hpp | 3 +- Modules/KiwiModel/KiwiModel_Objects.cpp | 26 +++++++++++++++ 7 files changed, 65 insertions(+), 12 deletions(-) diff --git a/Client/Source/KiwiApp_DspDeviceManager.cpp b/Client/Source/KiwiApp_DspDeviceManager.cpp index a0479377..fc0c1d88 100644 --- a/Client/Source/KiwiApp_DspDeviceManager.cpp +++ b/Client/Source/KiwiApp_DspDeviceManager.cpp @@ -110,15 +110,11 @@ namespace kiwi return m_is_playing; }; - void DspDeviceManager::addSignal(dsp::Buffer const& output_buffer) + void DspDeviceManager::addToChannel(size_t const channel, dsp::Signal const& output_signal) { - if (output_buffer.getNumberOfChannels() == m_output_matrix->getNumberOfChannels() - && output_buffer.getVectorSize() == m_output_matrix->getVectorSize()) + if (channel < m_output_matrix->getNumberOfChannels() && output_signal.size() == m_output_matrix->getVectorSize()) { - for(int channel_index = 0; channel_index < m_output_matrix->getNumberOfChannels(); ++channel_index) - { - (*m_output_matrix)[channel_index].add(output_buffer[channel_index]); - } + (*m_output_matrix)[channel].add(output_signal); } } diff --git a/Client/Source/KiwiApp_DspDeviceManager.hpp b/Client/Source/KiwiApp_DspDeviceManager.hpp index 1a3db777..966038e0 100644 --- a/Client/Source/KiwiApp_DspDeviceManager.hpp +++ b/Client/Source/KiwiApp_DspDeviceManager.hpp @@ -72,7 +72,7 @@ namespace kiwi bool isAudioOn() const override; //! @brief Adds a buffer to the output matrix of signal. - void addSignal(dsp::Buffer const& output_buffer) override; + void addToChannel(size_t const channel, dsp::Signal const& output_buffer) override; private: // methods diff --git a/Client/Source/KiwiApp_PatcherView.cpp b/Client/Source/KiwiApp_PatcherView.cpp index 9408540c..a5ca26bd 100755 --- a/Client/Source/KiwiApp_PatcherView.cpp +++ b/Client/Source/KiwiApp_PatcherView.cpp @@ -1908,7 +1908,7 @@ namespace kiwi } catch(...) { - return m_patcher_model.addObject("errorbox", std::vector(atoms.begin()+1, atoms.end())); + return m_patcher_model.addObject("errorbox", std::vector(atoms.begin(), atoms.end())); } return *model; } diff --git a/Modules/KiwiEngine/KiwiEngine_AudioControler.hpp b/Modules/KiwiEngine/KiwiEngine_AudioControler.hpp index dc39bea1..81d6fcec 100644 --- a/Modules/KiwiEngine/KiwiEngine_AudioControler.hpp +++ b/Modules/KiwiEngine/KiwiEngine_AudioControler.hpp @@ -59,7 +59,7 @@ namespace kiwi virtual void remove(dsp::Chain& chain) = 0; //! @brief Adds a signal to the output_buffer of the AudioControler. - virtual void addSignal(dsp::Buffer const& output_buffer) = 0; + virtual void addToChannel(size_t const channel, dsp::Signal const& output_signal) = 0; private: // deleted methods diff --git a/Modules/KiwiEngine/KiwiEngine_Objects.cpp b/Modules/KiwiEngine/KiwiEngine_Objects.cpp index 73ad0bc2..a166e06d 100644 --- a/Modules/KiwiEngine/KiwiEngine_Objects.cpp +++ b/Modules/KiwiEngine/KiwiEngine_Objects.cpp @@ -234,8 +234,35 @@ namespace kiwi DacTilde::DacTilde(model::Object const& model, Patcher& patcher, std::vector const& args): AudioObject(model, patcher), + m_router(), m_audio_controler(patcher.getAudioControler()) { + for(Atom const& arg : args) + { + if (arg.isNumber()) + { + m_router.push_back(arg.getInt() - 1); + } + else if(arg.isString()) + { + std::string inputs(arg.getString()); + + int left_input = std::stoi(inputs.substr(0, inputs.find(":"))) - 1; + int right_input = std::stoi(inputs.substr(inputs.find(":") + 1)) - 1; + + bool rev = left_input > right_input; + + for (int channel = left_input; rev ? channel >= right_input : channel <= right_input; rev ? --channel : ++channel) + { + m_router.push_back(channel); + } + } + } + + if (m_router.empty()) + { + m_router = {0, 1}; + } } void DacTilde::receive(size_t, std::vector const& args) @@ -259,7 +286,10 @@ namespace kiwi void DacTilde::perform(dsp::Buffer const& input, dsp::Buffer& output) noexcept { - m_audio_controler.addSignal(input); + for (int inlet_number = 0; inlet_number < input.getNumberOfChannels(); ++inlet_number) + { + m_audio_controler.addToChannel(m_router[inlet_number], input[inlet_number]); + } } void DacTilde::prepare(dsp::Processor::PrepareInfo const& infos) diff --git a/Modules/KiwiEngine/KiwiEngine_Objects.hpp b/Modules/KiwiEngine/KiwiEngine_Objects.hpp index de551913..14c604ba 100644 --- a/Modules/KiwiEngine/KiwiEngine_Objects.hpp +++ b/Modules/KiwiEngine/KiwiEngine_Objects.hpp @@ -169,7 +169,8 @@ namespace kiwi void prepare(dsp::Processor::PrepareInfo const& infos) override final; private: - engine::AudioControler& m_audio_controler; + std::vector m_router; + engine::AudioControler& m_audio_controler; }; // ================================================================================ // diff --git a/Modules/KiwiModel/KiwiModel_Objects.cpp b/Modules/KiwiModel/KiwiModel_Objects.cpp index 18332b9e..daa09559 100755 --- a/Modules/KiwiModel/KiwiModel_Objects.cpp +++ b/Modules/KiwiModel/KiwiModel_Objects.cpp @@ -202,8 +202,34 @@ namespace kiwi { if(atom.isNumber()) { + if (atom.getInt() <= 0) + { + throw std::runtime_error("null or negative channel"); + } + channels++; } + else if(atom.isString()) + { + std::string inputs(atom.getString()); + + size_t sep_pos = inputs.find(":"); + + if (sep_pos == std::string::npos) + { + throw std::runtime_error("wrong symbol syntax"); + } + + int left_input = std::stoi(inputs.substr(0, sep_pos)); + int right_input = std::stoi(inputs.substr(inputs.find(":") + 1)); + + if (left_input <= 0 || right_input <= 0) + { + throw std::runtime_error("null or negative channel"); + } + + channels += std::abs(right_input - left_input) + 1; + } } if(channels == 0) channels = 2; From a0869056036ab4fc132c0b2d2cafc9c4b5f282e9 Mon Sep 17 00:00:00 2001 From: jean-millot Date: Tue, 15 Nov 2016 18:07:39 +0100 Subject: [PATCH 2/2] Increasing the maximum number of input and output for device manager. --- Client/Source/KiwiApp_DspDeviceManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Client/Source/KiwiApp_DspDeviceManager.cpp b/Client/Source/KiwiApp_DspDeviceManager.cpp index fc0c1d88..bac9fbe0 100644 --- a/Client/Source/KiwiApp_DspDeviceManager.cpp +++ b/Client/Source/KiwiApp_DspDeviceManager.cpp @@ -43,11 +43,11 @@ namespace kiwi if (previous_settings) { - initialise(2, 2, previous_settings, false); + initialise(256, 256, previous_settings, false); } else { - initialiseWithDefaultDevices(2, 2); + initialiseWithDefaultDevices(256, 256); } }