2#include <Media/AudioDecoder.hpp>
4#include <score/document/DocumentContext.hpp>
5#include <score/tools/File.hpp>
7#include <ossia/dataflow/exec_state_facade.hpp>
8#include <ossia/dataflow/nodes/media.hpp>
9#include <ossia/network/value/value.hpp>
14#include <avnd/binding/ossia/soundfiles.hpp>
15#include <libremidi/reader.hpp>
22[[nodiscard]]
static QString
25 if(
auto str = value.target<std::string>())
35[[nodiscard]]
static ossia::value
38 if(
auto str = value.target<std::string>(); str && !str->empty())
40 const QString resolved
42 if(!resolved.isEmpty())
43 return ossia::value{resolved.toStdString()};
49[[nodiscard]]
static auto
53 if(
auto str = filenameFromPort(value, ctx); !str.isEmpty())
55 auto dec = Media::AudioDecoder::decode_synchronous(str, rate);
59 auto hdl = std::make_shared<ossia::audio_data>();
60 hdl->data = std::move(dec->second);
61 hdl->path = str.toStdString();
66 return ossia::audio_handle{};
69using midifile_handle = std::shared_ptr<oscr::midifile_data>;
70[[nodiscard]]
inline midifile_handle
74 if(
auto str = filenameFromPort(value, ctx); !str.isEmpty())
77 if(!f.open(QIODevice::ReadOnly))
79 auto ptr = f.map(0, f.size());
81 auto hdl = std::make_shared<oscr::midifile_data>();
82 if(
auto ret = hdl->reader.parse((uint8_t*)ptr, f.size());
83 ret == libremidi::reader::invalid)
86 hdl->filename = str.toStdString();
92using raw_file_handle = std::shared_ptr<raw_file_data>;
93[[nodiscard]]
inline raw_file_handle loadRawfile(
97 if(
auto filename = filenameFromPort(value, ctx); !filename.isEmpty())
99 if(!QFile::exists(filename))
102 auto hdl = std::make_shared<oscr::raw_file_data>();
103 hdl->file.setFileName(filename);
104 if(!hdl->file.open(QIODevice::ReadOnly))
109 auto map = (
char*)hdl->file.map(0, hdl->file.size());
110 hdl->data = QByteArray::fromRawData(map, hdl->file.size());
115 hdl->file.setTextModeEnabled(
true);
117 hdl->data = hdl->file.readAll();
119 hdl->filename = filename.toStdString();
125[[nodiscard]]
inline auto loadSoundfile(
127 const std::shared_ptr<ossia::execution_state>& st)
129 const double rate = ossia::exec_state_facade{st.get()}.sampleRate();
130 return loadSoundfile(value, ctx, rate);
133template <
typename Field>
134static auto executePortPreprocess(
auto& file)
136 using field_file_type =
decltype(Field::file);
137 field_file_type ffile;
138 ffile.bytes =
decltype(ffile.bytes)(file.data.constData(), file.file.size());
139 ffile.filename = file.filename;
140 return Field::process(ffile);
Definition Factories.hpp:19
QString locateFilePath(const QString &filename, const score::DocumentContext &ctx) noexcept
Definition File.cpp:83
Definition DocumentContext.hpp:18