19 : eventDistributor(eventDistributor_), scheduler(scheduler_)
20 , readFilenameSetting(
21 commandController,
"midi-in-readfilename",
22 "filename of the file where the MIDI input is read from",
38 throw PlugException(
"Failed to open input: ", strerror(errno));
41 auto& midiConnector = checked_cast<MidiInConnector&>(connector_);
49 thread = std::thread([
this]() { run(); });
61 return "midi-in-reader";
66 return "MIDI in file reader. Sends data from an input file to the "
67 "MIDI port it is connected to. The filename is set with "
68 "the 'midi-in-readfilename' setting.";
72void MidiInReader::run()
77 if (poller.
poll(fileno(file.get()))) {
81 std::array<uint8_t, 1> buf;
82 size_t num = fread(buf.data(),
sizeof(uint8_t), buf.size(), file.get());
92 std::scoped_lock lock(mutex);
102 auto* conn = checked_cast<MidiInConnector*>(
getConnector());
103 if (!conn->acceptsData()) {
104 std::scoped_lock lock(mutex);
108 if (!conn->ready()) {
114 std::scoped_lock lock(mutex);
115 if (queue.
empty())
return;
118 conn->recvByte(data, time);
122bool MidiInReader::signalEvent(
const Event& )
127 std::scoped_lock lock(mutex);
134template<
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=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.
void setConnector(Connector *conn)
Connector * getConnector() const
Get the connector this Pluggable is plugged into.
bool poll(int fd)
Waits for an event to occur on the given file descriptor.
void reset()
Reset aborted() to false.
bool aborted() const
Returns true iff abort() was called.
void abort()
Aborts a poll in progress and any future poll attempts.
EmuTime::param getCurrentTime() const
Get the current scheduler time.
FILE_t openFile(zstring_view filename, zstring_view mode)
Call fopen() in a platform-independent manner.
This file implemented 3 utility functions:
std::variant< KeyUpEvent, KeyDownEvent, MouseMotionEvent, MouseButtonUpEvent, MouseButtonDownEvent, MouseWheelEvent, JoystickAxisMotionEvent, JoystickHatEvent, JoystickButtonUpEvent, JoystickButtonDownEvent, OsdControlReleaseEvent, OsdControlPressEvent, WindowEvent, TextEvent, FileDropEvent, QuitEvent, FinishFrameEvent, CliCommandEvent, GroupEvent, BootEvent, FrameDrawnEvent, BreakEvent, SwitchRendererEvent, TakeReverseSnapshotEvent, AfterTimedEvent, MachineLoadedEvent, MachineActivatedEvent, MachineDeactivatedEvent, MidiInReaderEvent, MidiInWindowsEvent, MidiInCoreMidiEvent, MidiInCoreMidiVirtualEvent, MidiInALSAEvent, Rs232TesterEvent, Rs232NetEvent, ImGuiDelayedActionEvent, ImGuiActiveEvent > Event
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)