#pragma once #include #include #include #include #include #include #include "device.h" #include "hotplug.h" namespace rawinput { // settings extern bool NOLEGACY; extern uint8_t HID_LIGHT_BRIGHTNESS; extern bool ENABLE_SMX_STAGE; extern int TOUCHSCREEN_RANGE_X; extern int TOUCHSCREEN_RANGE_Y; struct DeviceCallback { void *data; std::function f; }; struct MidiCallback { void *data; std::function f; }; class RawInputManager { private: HotplugManager *hotplug; std::vector devices; HWND input_hwnd = nullptr; WNDCLASSEX input_hwnd_class {}; std::thread *input_thread = nullptr; std::thread *flush_thread = nullptr; bool flush_thread_running = false; std::thread *output_thread = nullptr; std::mutex output_thread_m; bool output_thread_ready = false; bool output_thread_running = false; std::condition_variable output_thread_cv; std::vector callback_add; std::vector callback_change; std::vector callback_midi; void input_hwnd_create(); void input_hwnd_destroy(); void devices_reload(); void devices_scan_rawinput(RAWINPUTDEVICELIST *device, bool log = true); void devices_scan_piuio(); void devices_scan_smxstage(); void devices_destruct(); void devices_destruct(Device *device, bool log = true); void flush_start(); void flush_stop(); void output_start(); void output_stop(); static std::string rawinput_get_device_name(HANDLE hDevice); static std::string rawinput_get_device_description(const DeviceInfo& info, const std::string &device_name); static LRESULT CALLBACK input_wnd_proc(HWND, UINT, WPARAM, LPARAM); static void CALLBACK input_midi_proc(HMIDIIN, UINT, DWORD_PTR, DWORD_PTR, DWORD_PTR); static DeviceInfo get_device_info(const std::string &device_name); public: RawInputManager(); ~RawInputManager(); void stop(); void sextet_register( const std::string &port_name, const std::string &alias = "Sextet", bool warn = true); void devices_scan_rawinput(const std::string &device_name = ""); void devices_scan_midi(); void devices_remove(const std::string &name); void devices_register(); void devices_unregister(); static void device_write_output(Device *device, bool only_updated = true); void devices_flush_output(bool optimized = true); void __stdcall devices_print(); Device *devices_get(const std::string &name, bool updated = false); inline std::vector &devices_get() { return devices; } inline std::vector devices_get_updated() { std::vector updated; for (auto &device : devices_get()) { device.mutex->lock(); if (device.updated) { device.updated = false; device.mutex->unlock(); updated.emplace_back(&device); } else { device.mutex->unlock(); } } return updated; } inline void devices_midi_freeze(bool freeze) { for (auto &device : devices_get()) { if (device.type == MIDI) { device.midiInfo->freeze = freeze; if (!freeze) { for (unsigned short index = 0; index < 16 * 128; index++) { device.midiInfo->states[index] = false; } } } } } void add_callback_add(void *data, std::function callback); void remove_callback_add(void *data, const std::function &callback); void add_callback_change(void *data, std::function callback); void remove_callback_change(void *data, const std::function& callback); void add_callback_midi(void *data, std::function callback); void remove_callback_midi(void *data, const std::function& callback); }; }