diff --git a/drivers/alsamidi/SCsub b/drivers/alsamidi/SCsub deleted file mode 100644 index 4e1b5f2..0000000 --- a/drivers/alsamidi/SCsub +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env python - -Import("env") - -# Driver source files -env.add_source_files(env.drivers_sources, "*.cpp") diff --git a/drivers/alsamidi/midi_driver_alsamidi.cpp b/drivers/alsamidi/midi_driver_alsamidi.cpp deleted file mode 100644 index 0ccca7d..0000000 --- a/drivers/alsamidi/midi_driver_alsamidi.cpp +++ /dev/null @@ -1,253 +0,0 @@ -/*************************************************************************/ -/* midi_driver_alsamidi.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifdef ALSAMIDI_ENABLED - -#include "midi_driver_alsamidi.h" - -#include "core/os/os.h" -#include "core/string/print_string.h" - -#include - -MIDIDriverALSAMidi::MessageCategory MIDIDriverALSAMidi::msg_category(uint8_t msg_part) { - if (msg_part >= 0xf8) { - return MessageCategory::RealTime; - } else if (msg_part >= 0xf0) { - // System Exclusive begin/end are specified as System Common Category messages, - // but we separate them here and give them their own categories as their - // behaviour is significantly different. - if (msg_part == 0xf0) { - return MessageCategory::SysExBegin; - } else if (msg_part == 0xf7) { - return MessageCategory::SysExEnd; - } - return MessageCategory::SystemCommon; - } else if (msg_part >= 0x80) { - return MessageCategory::Voice; - } - return MessageCategory::Data; -} - -size_t MIDIDriverALSAMidi::msg_expected_data(uint8_t status_byte) { - if (msg_category(status_byte) == MessageCategory::Voice) { - // Voice messages have a channel number in the status byte, mask it out. - status_byte &= 0xf0; - } - - switch (status_byte) { - case 0x80: // Note Off - case 0x90: // Note On - case 0xA0: // Polyphonic Key Pressure (Aftertouch) - case 0xB0: // Control Change (CC) - case 0xE0: // Pitch Bend Change - case 0xF2: // Song Position Pointer - return 2; - - case 0xC0: // Program Change - case 0xD0: // Channel Pressure (Aftertouch) - case 0xF1: // MIDI Time Code Quarter Frame - case 0xF3: // Song Select - return 1; - } - - return 0; -} - -void MIDIDriverALSAMidi::InputConnection::parse_byte(uint8_t byte, MIDIDriverALSAMidi &driver, - uint64_t timestamp) { - switch (msg_category(byte)) { - case MessageCategory::RealTime: - // Real-Time messages are single byte messages that can - // occur at any point. - // We pass them straight through. - driver.receive_input_packet(timestamp, &byte, 1); - break; - - case MessageCategory::Data: - // We don't currently forward System Exclusive messages so skip their data. - // Collect any expected data for other message types. - if (!skipping_sys_ex && expected_data > received_data) { - buffer[received_data + 1] = byte; - received_data++; - - // Forward a complete message and reset relevant state. - if (received_data == expected_data) { - driver.receive_input_packet(timestamp, buffer, received_data + 1); - received_data = 0; - - if (msg_category(buffer[0]) != MessageCategory::Voice) { - // Voice Category messages can be sent with "running status". - // This means they don't resend the status byte until it changes. - // For other categories, we reset expected data, to require a new status byte. - expected_data = 0; - } - } - } - break; - - case MessageCategory::SysExBegin: - buffer[0] = byte; - skipping_sys_ex = true; - break; - - case MessageCategory::SysExEnd: - expected_data = 0; - skipping_sys_ex = false; - break; - - case MessageCategory::Voice: - case MessageCategory::SystemCommon: - buffer[0] = byte; - received_data = 0; - expected_data = msg_expected_data(byte); - skipping_sys_ex = false; - if (expected_data == 0) { - driver.receive_input_packet(timestamp, &byte, 1); - } - break; - } -} - -int MIDIDriverALSAMidi::InputConnection::read_in(MIDIDriverALSAMidi &driver, uint64_t timestamp) { - int ret; - do { - uint8_t byte = 0; - ret = snd_rawmidi_read(rawmidi_ptr, &byte, 1); - - if (ret < 0) { - if (ret != -EAGAIN) { - ERR_PRINT("snd_rawmidi_read error: " + String(snd_strerror(ret))); - } - } else { - parse_byte(byte, driver, timestamp); - } - } while (ret > 0); - - return ret; -} - -void MIDIDriverALSAMidi::thread_func(void *p_udata) { - MIDIDriverALSAMidi *md = (MIDIDriverALSAMidi *)p_udata; - uint64_t timestamp = 0; - - while (!md->exit_thread.is_set()) { - md->lock(); - - InputConnection *connections = md->connected_inputs.ptrw(); - size_t connection_count = md->connected_inputs.size(); - - for (size_t i = 0; i < connection_count; i++) { - connections[i].read_in(*md, timestamp); - } - - md->unlock(); - - OS::get_singleton()->delay_usec(1000); - } -} - -Error MIDIDriverALSAMidi::open() { - void **hints; - - if (snd_device_name_hint(-1, "rawmidi", &hints) < 0) { - return ERR_CANT_OPEN; - } - - int i = 0; - for (void **n = hints; *n != nullptr; n++) { - char *name = snd_device_name_get_hint(*n, "NAME"); - - if (name != nullptr) { - snd_rawmidi_t *midi_in; - int ret = snd_rawmidi_open(&midi_in, nullptr, name, SND_RAWMIDI_NONBLOCK); - if (ret >= 0) { - connected_inputs.insert(i++, InputConnection(midi_in)); - } - } - - if (name != nullptr) { - free(name); - } - } - snd_device_name_free_hint(hints); - - exit_thread.clear(); - thread.start(MIDIDriverALSAMidi::thread_func, this); - - return OK; -} - -void MIDIDriverALSAMidi::close() { - exit_thread.set(); - thread.wait_to_finish(); - - for (int i = 0; i < connected_inputs.size(); i++) { - snd_rawmidi_t *midi_in = connected_inputs[i].rawmidi_ptr; - snd_rawmidi_close(midi_in); - } - connected_inputs.clear(); -} - -void MIDIDriverALSAMidi::lock() const { - mutex.lock(); -} - -void MIDIDriverALSAMidi::unlock() const { - mutex.unlock(); -} - -PoolStringArray MIDIDriverALSAMidi::get_connected_inputs() { - PoolStringArray list; - - lock(); - for (int i = 0; i < connected_inputs.size(); i++) { - snd_rawmidi_t *midi_in = connected_inputs[i].rawmidi_ptr; - snd_rawmidi_info_t *info; - - snd_rawmidi_info_malloc(&info); - snd_rawmidi_info(midi_in, info); - list.push_back(snd_rawmidi_info_get_name(info)); - snd_rawmidi_info_free(info); - } - unlock(); - - return list; -} - -MIDIDriverALSAMidi::MIDIDriverALSAMidi() { - exit_thread.clear(); -} - -MIDIDriverALSAMidi::~MIDIDriverALSAMidi() { - close(); -} - -#endif // ALSAMIDI_ENABLED diff --git a/drivers/alsamidi/midi_driver_alsamidi.h b/drivers/alsamidi/midi_driver_alsamidi.h deleted file mode 100644 index 20d026d..0000000 --- a/drivers/alsamidi/midi_driver_alsamidi.h +++ /dev/null @@ -1,105 +0,0 @@ -#ifndef MIDI_DRIVER_ALSAMIDI_H -#define MIDI_DRIVER_ALSAMIDI_H -/*************************************************************************/ -/* midi_driver_alsamidi.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifdef ALSAMIDI_ENABLED - -#include "core/os/midi_driver.h" -#include "core/os/mutex.h" -#include "core/os/thread.h" -#include "core/os/safe_refcount.h" -#include "core/containers/vector.h" - -#include "../alsa/asound-so_wrap.h" -#include - -class MIDIDriverALSAMidi : public MIDIDriver { - Thread thread; - Mutex mutex; - - class InputConnection { - public: - InputConnection() = default; - InputConnection(snd_rawmidi_t *midi_in) : - rawmidi_ptr{ midi_in } {} - - // Read in and parse available data, forwarding any complete messages through the driver. - int read_in(MIDIDriverALSAMidi &driver, uint64_t timestamp); - - snd_rawmidi_t *rawmidi_ptr = nullptr; - - private: - static const size_t MSG_BUFFER_SIZE = 3; - uint8_t buffer[MSG_BUFFER_SIZE] = { 0 }; - size_t expected_data = 0; - size_t received_data = 0; - bool skipping_sys_ex = false; - void parse_byte(uint8_t byte, MIDIDriverALSAMidi &driver, uint64_t timestamp); - }; - - Vector connected_inputs; - - SafeFlag exit_thread; - - static void thread_func(void *p_udata); - - enum class MessageCategory { - Data, - Voice, - SysExBegin, - SystemCommon, // excluding System Exclusive Begin/End - SysExEnd, - RealTime, - }; - - // If the passed byte is a status byte, return the associated message category, - // else return MessageCategory::Data. - static MessageCategory msg_category(uint8_t msg_part); - - // Return the number of data bytes expected for the provided status byte. - static size_t msg_expected_data(uint8_t status_byte); - - void lock() const; - void unlock() const; - -public: - virtual Error open(); - virtual void close(); - - virtual PoolStringArray get_connected_inputs(); - - MIDIDriverALSAMidi(); - virtual ~MIDIDriverALSAMidi(); -}; - -#endif // ALSAMIDI_ENABLED - -#endif // MIDI_DRIVER_ALSAMIDI_H diff --git a/drivers/pulseaudio/audio_driver_pulseaudio.cpp b/drivers/pulseaudio/audio_driver_pulseaudio.cpp index 5071823..5470820 100644 --- a/drivers/pulseaudio/audio_driver_pulseaudio.cpp +++ b/drivers/pulseaudio/audio_driver_pulseaudio.cpp @@ -36,10 +36,6 @@ #include "core/config/project_settings.h" #include "core/version.h" -#ifdef ALSAMIDI_ENABLED -#include "drivers/alsa/asound-so_wrap.h" -#endif - void AudioDriverPulseAudio::pa_state_cb(pa_context *c, void *userdata) { AudioDriverPulseAudio *ad = (AudioDriverPulseAudio *)userdata; @@ -277,10 +273,7 @@ Error AudioDriverPulseAudio::init() { #else int dylibloader_verbose = 0; #endif -#ifdef ALSAMIDI_ENABLED - // If using PulseAudio with ALSA MIDI, we need to initialize ALSA as well - initialize_asound(dylibloader_verbose); -#endif + if (initialize_pulse(dylibloader_verbose)) { return ERR_CANT_OPEN; } diff --git a/platform/x11/detect.py b/platform/x11/detect.py index aad11c8..e10cbf0 100644 --- a/platform/x11/detect.py +++ b/platform/x11/detect.py @@ -338,7 +338,7 @@ def configure(env): if os.system("pkg-config --exists alsa") == 0: # 0 means found env["alsa"] = True - env.Append(CPPDEFINES=["ALSA_ENABLED", "ALSAMIDI_ENABLED"]) + env.Append(CPPDEFINES=["ALSA_ENABLED"]) env.ParseConfig("pkg-config alsa --cflags") # Only cflags, we dlopen the library. else: print("Warning: ALSA libraries not found. Disabling the ALSA audio driver.") diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 5846c96..9edaf84 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -821,9 +821,6 @@ void OS_X11::finalize() { memdelete(debugger_connection_console); } */ -#ifdef ALSAMIDI_ENABLED - driver_alsamidi.close(); -#endif #ifdef JOYDEV_ENABLED memdelete(joypad); diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index e24346b..669bad5 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -35,7 +35,6 @@ #include "core/input/input.h" #include "crash_handler_x11.h" #include "drivers/alsa/audio_driver_alsa.h" -#include "drivers/alsamidi/midi_driver_alsamidi.h" #include "drivers/pulseaudio/audio_driver_pulseaudio.h" #include "drivers/unix/os_unix.h" #include "joypad_linux.h" @@ -205,10 +204,6 @@ class OS_X11 : public OS_Unix { AudioDriverALSA driver_alsa; #endif -#ifdef ALSAMIDI_ENABLED - MIDIDriverALSAMidi driver_alsamidi; -#endif - #ifdef PULSEAUDIO_ENABLED AudioDriverPulseAudio driver_pulseaudio; #endif