Skip to content

Commit

Permalink
Merge pull request #45 from Musicoll/dev/master
Browse files Browse the repository at this point in the history
Dev/master
  • Loading branch information
jean-millot authored Nov 16, 2016
2 parents 2a23f5b + dba7441 commit a1e3e97
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 14 deletions.
14 changes: 5 additions & 9 deletions Client/Source/KiwiApp_DspDeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Client/Source/KiwiApp_DspDeviceManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Client/Source/KiwiApp_PatcherView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1908,7 +1908,7 @@ namespace kiwi
}
catch(...)
{
return m_patcher_model.addObject("errorbox", std::vector<Atom>(atoms.begin()+1, atoms.end()));
return m_patcher_model.addObject("errorbox", std::vector<Atom>(atoms.begin(), atoms.end()));
}
return *model;
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/KiwiEngine/KiwiEngine_AudioControler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
32 changes: 31 additions & 1 deletion Modules/KiwiEngine/KiwiEngine_Objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,35 @@ namespace kiwi

DacTilde::DacTilde(model::Object const& model, Patcher& patcher, std::vector<Atom> 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<Atom> const& args)
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion Modules/KiwiEngine/KiwiEngine_Objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ namespace kiwi
void prepare(dsp::Processor::PrepareInfo const& infos) override final;

private:
engine::AudioControler& m_audio_controler;
std::vector<size_t> m_router;
engine::AudioControler& m_audio_controler;
};

// ================================================================================ //
Expand Down
26 changes: 26 additions & 0 deletions Modules/KiwiModel/KiwiModel_Objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a1e3e97

Please sign in to comment.