Fixed crushing midi outputs
This commit is contained in:
parent
07fa4f894a
commit
25cf883d03
@ -605,7 +605,6 @@ static Result<Value> builtin_scan(Interpreter &interpreter, std::vector<Value> a
|
||||
static Result<Value> builtin_concurrent(Interpreter &interpreter, std::span<Ast> args)
|
||||
{
|
||||
auto const jobs_count = args.size();
|
||||
std::vector<std::jthread> threads;
|
||||
std::vector<std::future<Value>> futures;
|
||||
std::optional<Error> error;
|
||||
std::mutex mutex;
|
||||
@ -613,7 +612,7 @@ static Result<Value> builtin_concurrent(Interpreter &interpreter, std::span<Ast>
|
||||
for (unsigned i = 0; i < jobs_count; ++i) {
|
||||
futures.push_back(std::async(std::launch::async, [interpreter = interpreter.clone(), i, args, &mutex, &error]() mutable -> Value {
|
||||
auto result = interpreter.eval((Ast)args[i]);
|
||||
if (result.has_value()) {
|
||||
if (result) {
|
||||
return *std::move(result);
|
||||
}
|
||||
|
||||
@ -621,7 +620,7 @@ static Result<Value> builtin_concurrent(Interpreter &interpreter, std::span<Ast>
|
||||
if (!error) {
|
||||
error = result.error();
|
||||
}
|
||||
return Value{};
|
||||
return Value{};
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <thread>
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <mutex>
|
||||
|
||||
#include <musique/format.hh>
|
||||
#include <musique/interpreter/env.hh>
|
||||
@ -188,7 +189,9 @@ struct Runner
|
||||
}
|
||||
}
|
||||
|
||||
Env::global->force_define("say", +[](Interpreter &interpreter, std::vector<Value> args) -> Result<Value> {
|
||||
Env::global->force_define("print", +[](Interpreter &interpreter, std::vector<Value> args) -> Result<Value> {
|
||||
static std::mutex stdio_mutex;
|
||||
std::lock_guard guard{stdio_mutex};
|
||||
for (auto it = args.begin(); it != args.end(); ++it) {
|
||||
std::cout << Try(format(interpreter, *it));
|
||||
if (std::next(it) != args.end())
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <musique/midi/midi.hh>
|
||||
#include <musique/errors.hh>
|
||||
#include <mutex>
|
||||
|
||||
// Copyright notice for RtMidi library
|
||||
__asm__(R"license(.ident "\
|
||||
@ -7,6 +8,8 @@ RtMidi: realtime MIDI i/o C++ classes\
|
||||
Copyright (c) 2003-2021 Gary P. Scavone"
|
||||
)license");
|
||||
|
||||
static std::mutex midi_output_mutex;
|
||||
|
||||
void midi::Rt_Midi::list_ports(std::ostream &out) const
|
||||
try {
|
||||
RtMidiIn input;
|
||||
@ -80,6 +83,7 @@ bool midi::Rt_Midi::supports_output() const
|
||||
template<std::size_t N>
|
||||
inline void send_message(RtMidiOut &out, std::array<std::uint8_t, N> message)
|
||||
try {
|
||||
std::lock_guard guard{midi_output_mutex};
|
||||
out.sendMessage(message.data(), message.size());
|
||||
} catch (RtMidiError &error) {
|
||||
// TODO(error)
|
||||
@ -97,13 +101,11 @@ enum : std::uint8_t
|
||||
|
||||
void midi::Rt_Midi::send_note_on(uint8_t channel, uint8_t note_number, uint8_t velocity)
|
||||
{
|
||||
std::cout << "NOTE ON " << int(channel) << '\t' << int(note_number) << '\t' << int(velocity) << std::endl;
|
||||
send_message(*output, std::array { std::uint8_t(Note_On + channel), note_number, velocity });
|
||||
}
|
||||
|
||||
void midi::Rt_Midi::send_note_off(uint8_t channel, uint8_t note_number, uint8_t velocity)
|
||||
{
|
||||
std::cout << "NOTE OFF " << int(channel) << '\t' << int(note_number) << '\t' << int(velocity) << std::endl;
|
||||
send_message(*output, std::array { std::uint8_t(Note_Off + channel), note_number, velocity });
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user