Skip to content

Commit

Permalink
recorder: use the local path logic. Fix #1655
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Jan 2, 2025
1 parent d86dfba commit e9d9e3e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
25 changes: 20 additions & 5 deletions src/plugins/score-plugin-avnd/AvndProcesses/AudioRecorder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ struct AudioRecorder
// Threaded worker
struct recorder_thread
{
explicit recorder_thread(const score::DocumentContext& context)
: context{context}
{
}
const score::DocumentContext& context;
ossia::drwav_write_handle f;
std::string filename;
std::string actual_filename;
Expand All @@ -43,8 +48,10 @@ struct AudioRecorder
if(must_record)
{
// Open the file with the correct substitutions
auto fname = QByteArray::fromStdString(this->filename);
fname.replace("%t", QDateTime::currentDateTimeUtc().toString().toUtf8());
auto fname = QString::fromStdString(this->filename);

fname.replace("%t", QDateTime::currentDateTimeUtc().toString());
fname = score::locateFilePath(fname, context);
actual_filename = fname.toStdString();
f.open(actual_filename, channels, rate, 16);
return false;
Expand Down Expand Up @@ -83,7 +90,7 @@ struct AudioRecorder
f.write_pcm_frames(frames, arr);
}
};
std::shared_ptr<recorder_thread> impl = std::make_shared<recorder_thread>();
std::shared_ptr<recorder_thread> impl;

struct reset_message
{
Expand Down Expand Up @@ -163,12 +170,20 @@ struct AudioRecorder
halp::callback<"Filename", std::string> finished;
} outputs;

const score::DocumentContext* ossia_document_context{};
int current_rate = 0;
void prepare(halp::setup s) { current_rate = s.rate; }
void prepare(halp::setup s)
{
current_rate = s.rate;
SCORE_ASSERT(ossia_document_context);
impl = std::make_shared<recorder_thread>(*ossia_document_context);
update();
}

void update()
{
worker.request(impl, reset_message{inputs.filename, current_rate, inputs.record});
if(impl)
worker.request(impl, reset_message{inputs.filename, current_rate, inputs.record});
}

void operator()(int frames)
Expand Down
1 change: 1 addition & 0 deletions src/plugins/score-plugin-avnd/Crousti/Executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class Executor final

if_possible(node->impl.effect.ossia_state = st);
if_possible(node->impl.effect.io_context = &net_ctx.context);
if_possible(node->impl.effect.ossia_document_context = &ctx.doc);
ptr.reset(node);
this->node = ptr;

Expand Down

0 comments on commit e9d9e3e

Please sign in to comment.