17 : eventDistributor(eventDistributor_), scheduler(scheduler_)
18 , readFilenameSetting(
19 commandController,
"midi-in-readfilename",
20 "filename of the file where the MIDI input is read from",
36 throw PlugException(
"Failed to open input: ", strerror(errno));
46 thread = std::thread([
this]() { run(); });
58 return "midi-in-reader";
63 return "MIDI in file reader. Sends data from an input file to the "
64 "MIDI port it is connected to. The filename is set with "
65 "the 'midi-in-readfilename' setting.";
69 void MidiInReader::run()
74 if (poller.
poll(fileno(file.get()))) {
79 size_t num = fread(buf, 1, 1, file.get());
89 std::lock_guard<std::mutex> lock(mutex);
93 Event::create<MidiInReaderEvent>());
101 if (!conn->acceptsData()) {
102 std::lock_guard<std::mutex> lock(mutex);
106 if (!conn->ready()) {
112 std::lock_guard<std::mutex> lock(mutex);
113 if (queue.
empty())
return;
116 conn->recvByte(data, time);
120 int MidiInReader::signalEvent(
const Event& ) noexcept
123 signal(scheduler.getCurrentTime());
125 std::lock_guard<std::mutex> lock(mutex);
132 template<
typename Archive>
Represents something you can plug devices into.
void unregisterEventListener(EventType type, EventListener &listener)
Unregisters a previously registered event listener.
void distributeEvent(Event &&event)
Schedule the given event for delivery.
void registerEventListener(EventType type, EventListener &listener, Priority priority=OTHER)
Registers a given object to receive certain events.
zstring_view getString() const noexcept
void serialize(Archive &ar, unsigned version)
std::string_view getName() const override
Name used to identify this pluggable.
void plugHelper(Connector &connector, EmuTime::param time) override
std::string_view getDescription() const override
Description for this pluggable.
void unplugHelper(EmuTime::param time) override
MidiInReader(EventDistributor &eventDistributor, Scheduler &scheduler, CommandController &commandController)
void signal(EmuTime::param time) override
Thrown when a plug action fails.
bool isPluggedIn() const
Returns true if this pluggable is currently plugged into a connector.
Connector * getConnector() const
Get the connector this Pluggable is plugged into.
void setConnector(Connector *conn)
bool poll(int fd)
Waits for an event to occur on the given file descriptor.
bool aborted()
Returns true iff abort() was called.
void abort()
Aborts a poll in progress and any future poll attempts.
virtual void setDataBits(DataBits bits)=0
FILE_t openFile(zstring_view filename, zstring_view mode)
Call fopen() in a platform-independent manner.
This file implemented 3 utility functions:
REGISTER_POLYMORPHIC_INITIALIZER(Pluggable, CassettePlayer, "CassettePlayer")
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)