@@ -37,16 +37,25 @@ class midi_access_emscripten
3737
3838 int input_count () const noexcept
3939 {
40+ if (!available ())
41+ return 0 ;
42+
4043 return EM_ASM_INT (return globalThis.__libreMidi_currentInputs .length ;);
4144 }
4245
4346 int output_count () const noexcept
4447 {
48+ if (!available ())
49+ return 0 ;
50+
4551 return EM_ASM_INT (return globalThis.__libreMidi_currentOutputs .length ;);
4652 }
4753
4854 void load_current_infos () noexcept
4955 {
56+ if (!available ())
57+ return ;
58+
5059#define get_js_string (variable_to_read, ...) \
5160 (char *)EM_ASM_INT ( \
5261 { \
@@ -206,6 +215,9 @@ class midi_access_emscripten
206215
207216 stdx::error send_message (int port_index, const char * bytes, int len)
208217 {
218+ if (!available ())
219+ return std::errc::operation_not_supported;
220+
209221 const auto & id = m_current_outputs[port_index].id ;
210222 EM_ASM (
211223 {
@@ -216,6 +228,8 @@ class midi_access_emscripten
216228 output.send (Array.from (bytes));
217229 },
218230 bytes, len, id.c_str ());
231+
232+ return stdx::error{};
219233 }
220234
221235 const std::vector<device_information>& inputs () const noexcept { return m_current_inputs; }
@@ -248,6 +262,9 @@ class midi_access_emscripten
248262
249263 void start_stream (int port_index)
250264 {
265+ if (!available ())
266+ return ;
267+
251268 // Isn't life great...
252269 // https://github.com/Planeshifter/emscripten-examples/tree/master/01_PassingArrays
253270 const auto & id = m_current_inputs[port_index].id ;
@@ -282,6 +299,9 @@ class midi_access_emscripten
282299
283300 void stop_stream (int port_index)
284301 {
302+ if (!available ())
303+ return ;
304+
285305 const auto & id = m_current_inputs[port_index].id ;
286306 EM_ASM (const id = UTF8ToString ($1 );
287307
0 commit comments