compatybility with old C++ on macos
This commit is contained in:
parent
01e0693031
commit
0bb1f22379
@ -167,7 +167,8 @@ struct Runner
|
||||
midi::Serial_Midi midi;
|
||||
Interpreter interpreter;
|
||||
std::shared_ptr<serialport::State> serial_state;
|
||||
std::optional<std::jthread> serial_event_loop;
|
||||
std::thread serial_event_loop;
|
||||
std::atomic<bool> serial_event_loop_stop = false;
|
||||
|
||||
/// Setup interpreter and midi connection with given port
|
||||
explicit Runner(std::optional<unsigned> output_port)
|
||||
@ -183,8 +184,8 @@ struct Runner
|
||||
midi.serialport = serial_state;
|
||||
serialport::initialize();
|
||||
|
||||
serial_event_loop = std::jthread([this](std::stop_token token) mutable{
|
||||
serialport::event_loop(token, *serial_state);
|
||||
serial_event_loop = std::thread([this]() mutable {
|
||||
serialport::event_loop(serial_event_loop_stop, *serial_state);
|
||||
});
|
||||
|
||||
interpreter.midi_connection = &midi;
|
||||
@ -209,6 +210,13 @@ struct Runner
|
||||
Runner& operator=(Runner const&) = delete;
|
||||
Runner& operator=(Runner &&) = delete;
|
||||
|
||||
~Runner() {
|
||||
serial_event_loop_stop = true;
|
||||
if (serial_event_loop.joinable()) {
|
||||
serial_event_loop.join();
|
||||
}
|
||||
}
|
||||
|
||||
/// Consider given input file as new definition of parametless function
|
||||
///
|
||||
/// Useful for deffering execution of files to the point when all configuration of midi devices
|
||||
|
@ -38,9 +38,9 @@ namespace serialport{
|
||||
return 8;
|
||||
}
|
||||
|
||||
void event_loop(std::stop_token token, State &state)
|
||||
void event_loop(std::atomic<bool> &stop, State &state)
|
||||
{
|
||||
while(!token.stop_requested()){
|
||||
while(!stop){
|
||||
try {
|
||||
/// Search for the right device
|
||||
auto const ports = serial::list_ports();
|
||||
@ -61,18 +61,18 @@ namespace serialport{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Start connection
|
||||
serial::Serial serial_conn(connection_port, 115200, serial::Timeout::simpleTimeout(1000));
|
||||
|
||||
|
||||
|
||||
|
||||
/*if(serial_conn.isOpen())
|
||||
std::cout << "[SERIAL] Serial open\n";
|
||||
else
|
||||
std::cout << "[SERIAL] Serial not open\n";
|
||||
|
||||
|
||||
std::cout << "[SERIAL] commence serial communication\n";
|
||||
*/
|
||||
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
#include <string>
|
||||
#include <serial/serial.h>
|
||||
#include <stop_token>
|
||||
#include <memory>
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
@ -24,10 +23,10 @@ namespace serialport{
|
||||
void send(uint8_t message_type, uint8_t note_number);
|
||||
void set(unsigned position, std::uint32_t value);
|
||||
};
|
||||
|
||||
|
||||
void initialize();
|
||||
void event_loop(std::stop_token token, State &state);
|
||||
void event_loop(std::atomic<bool> &stop, State &state);
|
||||
std::uint8_t get_byte();
|
||||
}
|
||||
|
||||
#endif //MUSIQUE_SERIALPORT_SERIALPORT_HH
|
||||
#endif //MUSIQUE_SERIALPORT_SERIALPORT_HH
|
||||
|
Loading…
Reference in New Issue
Block a user