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>())
31 [[nodiscard]]
static auto
35 if(
auto str = filenameFromPort(value, ctx); !str.isEmpty())
37 auto dec = Media::AudioDecoder::decode_synchronous(str, rate);
41 auto hdl = std::make_shared<ossia::audio_data>();
42 hdl->data = std::move(dec->second);
43 hdl->path = str.toStdString();
48 return ossia::audio_handle{};
51 using midifile_handle = std::shared_ptr<oscr::midifile_data>;
52 [[nodiscard]]
inline midifile_handle
56 if(
auto str = filenameFromPort(value, ctx); !str.isEmpty())
59 if(!f.open(QIODevice::ReadOnly))
61 auto ptr = f.map(0, f.size());
63 auto hdl = std::make_shared<oscr::midifile_data>();
64 if(
auto ret = hdl->reader.parse((uint8_t*)ptr, f.size());
65 ret == libremidi::reader::invalid)
68 hdl->filename = str.toStdString();
74 using raw_file_handle = std::shared_ptr<raw_file_data>;
75 [[nodiscard]]
inline raw_file_handle loadRawfile(
79 if(
auto filename = filenameFromPort(value, ctx); !filename.isEmpty())
81 if(!QFile::exists(filename))
84 auto hdl = std::make_shared<oscr::raw_file_data>();
85 hdl->file.setFileName(filename);
86 if(!hdl->file.open(QIODevice::ReadOnly))
91 auto map = (
char*)hdl->file.map(0, hdl->file.size());
92 hdl->data = QByteArray::fromRawData(map, hdl->file.size());
97 hdl->file.setTextModeEnabled(
true);
99 hdl->data = hdl->file.readAll();
101 hdl->filename = filename.toStdString();
107 [[nodiscard]]
inline auto loadSoundfile(
109 const std::shared_ptr<ossia::execution_state>& st)
111 const double rate = ossia::exec_state_facade{st.get()}.sampleRate();
112 return loadSoundfile(value, ctx, rate);
115 template <
typename Field>
116 static auto executePortPreprocess(
auto& file)
118 using field_file_type = decltype(Field::file);
119 field_file_type ffile;
120 ffile.bytes = decltype(ffile.bytes)(file.data.constData(), file.file.size());
121 ffile.filename = file.filename;
122 return Field::process(ffile);
Definition: Factories.hpp:19
QString locateFilePath(const QString &filename, const score::DocumentContext &ctx) noexcept
Definition: File.cpp:57
Definition: DocumentContext.hpp:18