Skip to content

Commit

Permalink
[tests] Fix scenario tests due to unpropagated change after interval …
Browse files Browse the repository at this point in the history
…stopped auto-ticking on start
  • Loading branch information
jcelerier committed Nov 3, 2024
1 parent fe010b8 commit 41e79d4
Show file tree
Hide file tree
Showing 14 changed files with 214 additions and 141 deletions.
42 changes: 0 additions & 42 deletions src/ossia/audio/audio_parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "audio_protocol.hpp"

#include <ossia/dataflow/execution_state.hpp>
#include <ossia/dataflow/nodes/sound.hpp>
#include <ossia/network/common/complex_type.hpp>

namespace ossia
Expand Down Expand Up @@ -165,45 +164,4 @@ mapped_audio_parameter::~mapped_audio_parameter()
= static_cast<ossia::audio_protocol&>(get_node().get_device().get_protocol());
proto.unregister_parameter(*this);
}

namespace snd
{
void do_fade(
bool start_discontinuous, bool end_discontinuous, audio_channel& ap,
std::size_t start, std::size_t end)
{
using namespace std;
if(end < start)
swap(start, end);
const auto decrement = (1. / (end - start));
double gain = 1.0;

if(!start_discontinuous && !end_discontinuous)
return;
else if(start_discontinuous && !end_discontinuous)
{
for(std::size_t j = start; j < end; j++)
{
ap[j] *= (1. - gain);
gain -= decrement;
}
}
else if(!start_discontinuous && end_discontinuous)
{
for(std::size_t j = start; j < end; j++)
{
ap[j] *= std::pow(2., gain) - 1.;
gain -= decrement;
}
}
else
{
for(std::size_t j = start; j < end; j++)
{
ap[j] *= (2. * (gain * (1. - gain)));
gain -= decrement;
}
}
}
}
}
43 changes: 43 additions & 0 deletions src/ossia/audio/fade.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "fade.hpp"
namespace ossia::snd
{

void do_fade(
bool start_discontinuous, bool end_discontinuous, audio_channel& ap,
std::size_t start, std::size_t end)
{
using namespace std;
if(end < start)
swap(start, end);
const auto decrement = (1. / (end - start));
double gain = 1.0;

if(!start_discontinuous && !end_discontinuous)
return;
else if(start_discontinuous && !end_discontinuous)
{
for(std::size_t j = start; j < end; j++)
{
ap[j] *= (1. - gain);
gain -= decrement;
}
}
else if(!start_discontinuous && end_discontinuous)
{
for(std::size_t j = start; j < end; j++)
{
ap[j] *= std::pow(2., gain) - 1.;
gain -= decrement;
}
}
else
{
for(std::size_t j = start; j < end; j++)
{
ap[j] *= (2. * (gain * (1. - gain)));
gain -= decrement;
}
}
}

}
10 changes: 10 additions & 0 deletions src/ossia/audio/fade.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once
#include <ossia/dataflow/nodes/media.hpp>

namespace ossia::snd
{
OSSIA_EXPORT
void do_fade(
bool start_discontinuous, bool end_discontinuous, audio_channel& ap,
std::size_t start, std::size_t end);
}
4 changes: 4 additions & 0 deletions src/ossia/dataflow/nodes/dummy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class dummy_node : public ossia::graph_node
dummy_node() = default;

void run(const token_request& t, exec_state_facade) noexcept override { }
std::string label() const noexcept override { return "dummy"; }
};

class dummy_audio_node : public ossia::graph_node
Expand All @@ -27,6 +28,7 @@ class dummy_audio_node : public ossia::graph_node
auto& o = *m_outlets[0]->target<ossia::audio_port>();
o = i;
}
std::string label() const noexcept override { return "dummy_audio_node"; }
};

class dummy_midi_node : public ossia::graph_node
Expand All @@ -44,6 +46,7 @@ class dummy_midi_node : public ossia::graph_node
auto o = m_outlets[0]->target<ossia::midi_port>();
o->messages = i->messages;
}
std::string label() const noexcept override { return "dummy_midi_node"; }
};

class dummy_value_node : public ossia::graph_node
Expand All @@ -61,6 +64,7 @@ class dummy_value_node : public ossia::graph_node
auto o = m_outlets[0]->target<ossia::value_port>();
o->set_data(i->get_data());
}
std::string label() const noexcept override { return "dummy_value_node"; }
};

}
1 change: 1 addition & 0 deletions src/ossia/dataflow/nodes/messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class messages final : public ossia::graph_node
public:
messages() { }

std::string label() const noexcept override { return "messages"; }
void run(const ossia::token_request&, ossia::exec_state_facade e) noexcept override
{
for(auto& msg : data)
Expand Down
1 change: 1 addition & 0 deletions src/ossia/dataflow/nodes/percentage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class percentage final : public ossia::nonowning_graph_node
m_outlets.push_back(&outlet);
}

std::string label() const noexcept override { return "percentage"; }
void run(const ossia::token_request& tk, ossia::exec_state_facade e) noexcept override
{
const auto [tick_start, d] = e.timings(tk);
Expand Down
7 changes: 1 addition & 6 deletions src/ossia/dataflow/nodes/sound.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <ossia/audio/fade.hpp>
#include <ossia/dataflow/audio_stretch_mode.hpp>
#include <ossia/dataflow/node_process.hpp>
#include <ossia/dataflow/nodes/media.hpp>
Expand Down Expand Up @@ -91,12 +92,6 @@ inline void perform_start_offset(const std::size_t start, ossia::audio_port& ap)
ap.get().insert(ap.get().begin(), start, ossia::audio_channel{});
}
}

OSSIA_EXPORT
void do_fade(
bool start_discontinuous, bool end_discontinuous, audio_channel& ap,
std::size_t start, std::size_t end);

}

template <typename T>
Expand Down
4 changes: 4 additions & 0 deletions src/ossia/editor/scenario/detail/scenario_execution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ void scenario::run_interval(
{
interval.tick_offset_speed_precomputed(max_tick, offset, tk);
}
else if(max_tick == 0_tv)
{
interval.tick_offset_speed_precomputed(max_tick, offset, tk);
}

const auto ot = ossia::time_value{int64_t(diff)};
const auto node_it = m_overticks.lower_bound(end_node);
Expand Down
1 change: 0 additions & 1 deletion src/ossia/editor/scenario/time_interval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include <boost/config.hpp>

#include <algorithm>
#include <csignal>

namespace ossia
Expand Down
6 changes: 5 additions & 1 deletion src/ossia_sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -668,10 +668,12 @@ set(OSSIA_DATAFLOW_HEADERS
"${CMAKE_CURRENT_SOURCE_DIR}/ossia/audio/audio_parameter.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ossia/audio/audio_engine.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ossia/audio/audio_device.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ossia/audio/audio_protocol.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ossia/audio/audio_tick.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ossia/audio/drwav_handle.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ossia/audio/drwav_write_handle.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ossia/audio/fade.hpp"

"${CMAKE_CURRENT_SOURCE_DIR}/ossia/audio/audio_protocol.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ossia/audio/alsa_protocol.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ossia/audio/dummy_protocol.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ossia/audio/jack_protocol.hpp"
Expand Down Expand Up @@ -782,6 +784,8 @@ set(OSSIA_DATAFLOW_SRCS
"${CMAKE_CURRENT_SOURCE_DIR}/ossia/audio/audio_protocol.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ossia/audio/audio_device.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ossia/audio/audio_engine.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ossia/audio/fade.cpp"

"${CMAKE_CURRENT_SOURCE_DIR}/ossia/dataflow/execution/execution_policy.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ossia/dataflow/execution/default_policy.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ossia/dataflow/execution/direct_policy.cpp"
Expand Down
4 changes: 3 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ if(OSSIA_DATAFLOW)
ossia_add_test(TickMethodTest "${CMAKE_CURRENT_SOURCE_DIR}/Dataflow/TickMethodTest.cpp")
ossia_add_test(TokenRequestTest "${CMAKE_CURRENT_SOURCE_DIR}/Dataflow/TokenRequestTest.cpp")
ossia_add_test(SoundTest "${CMAKE_CURRENT_SOURCE_DIR}/Dataflow/SoundTest.cpp")
target_link_libraries(ossia_SoundTest PRIVATE rubberband samplerate)
if(TARGET rubberband AND TARGET samplerate)
target_link_libraries(ossia_SoundTest PRIVATE rubberband samplerate)
endif()
endif()

if(OSSIA_QML)
Expand Down
Loading

0 comments on commit 41e79d4

Please sign in to comment.