Skip to content

Commit

Permalink
[avnd] Add a loop mode to CSV Recorder playback mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Jun 10, 2024
1 parent 5ae5b43 commit f4eba84
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/plugins/score-plugin-avnd/AvndProcesses/DeviceRecorder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ struct DeviceRecorder : PatternObject
boost::container::flat_map<int, ossia::net::parameter_base*> m_map;
boost::container::flat_map<int64_t, std::vector<ossia::value>> m_vec;
bool active{};
bool loops{};
int num_params{};

void setActive(bool b)
Expand All @@ -546,6 +547,7 @@ struct DeviceRecorder : PatternObject
reopen();
}

void setLoops(bool b) { loops = b; }
void reopen()
{
f.close();
Expand Down Expand Up @@ -664,11 +666,16 @@ struct DeviceRecorder : PatternObject

void read()
{
if(m_vec.empty())
return;

using namespace std::chrono;
const auto ts
= duration_cast<milliseconds>(steady_clock::now() - first_ts).count();
auto ts = duration_cast<milliseconds>(steady_clock::now() - first_ts).count();
if(loops)
ts %= m_vec.rbegin()->first + 1;
read(ts);
}

void read(int64_t timestamp)
{
auto it = m_vec.lower_bound(timestamp);
Expand Down Expand Up @@ -703,7 +710,7 @@ struct DeviceRecorder : PatternObject
} filename;
struct
{
halp__enum("Mode", None, None, Record, Playback)
halp__enum("Mode", None, None, Record, Playback, Loop)
void update(DeviceRecorder& self) { self.setMode(); }
} mode;
} inputs;
Expand Down Expand Up @@ -767,7 +774,8 @@ struct DeviceRecorder : PatternObject
void operator()()
{
recorder->setActive(mode == mode_type::Record);
player->setActive(mode == mode_type::Playback);
player->setActive(mode == mode_type::Playback || mode == mode_type::Loop);
player->setLoops(mode == mode_type::Loop);
}
};

Expand Down Expand Up @@ -825,6 +833,7 @@ struct DeviceRecorder : PatternObject
worker.request(process_message{record_impl});
break;
case decltype(inputs.mode)::Playback:
case decltype(inputs.mode)::Loop:
worker.request(playback_message{play_impl});
break;
}
Expand Down

0 comments on commit f4eba84

Please sign in to comment.