summaryrefslogtreecommitdiff
path: root/core/os
diff options
context:
space:
mode:
Diffstat (limited to 'core/os')
-rw-r--r--core/os/midi_driver.cpp48
-rw-r--r--core/os/midi_driver.h1
-rw-r--r--core/os/os.cpp8
-rw-r--r--core/os/os.h10
4 files changed, 50 insertions, 17 deletions
diff --git a/core/os/midi_driver.cpp b/core/os/midi_driver.cpp
index 7cb7ae130f..81871d6c4f 100644
--- a/core/os/midi_driver.cpp
+++ b/core/os/midi_driver.cpp
@@ -33,6 +33,7 @@
#include "core/os/os.h"
#include "main/input_default.h"
+uint8_t MIDIDriver::last_received_message = 0x00;
MIDIDriver *MIDIDriver::singleton = NULL;
MIDIDriver *MIDIDriver::get_singleton() {
@@ -48,33 +49,42 @@ void MIDIDriver::receive_input_packet(uint64_t timestamp, uint8_t *data, uint32_
Ref<InputEventMIDI> event;
event.instance();
+ uint32_t param_position = 1;
if (length >= 1) {
- event->set_channel(data[0] & 0xF);
- event->set_message(data[0] >> 4);
+ if ((data[0] & 0x80) == 0x00) {
+ // running status
+ event->set_channel(last_received_message & 0xF);
+ event->set_message(last_received_message >> 4);
+ param_position = 0;
+ } else {
+ event->set_channel(data[0] & 0xF);
+ event->set_message(data[0] >> 4);
+ param_position = 1;
+ last_received_message = data[0];
+ }
}
switch (event->get_message()) {
case MIDI_MESSAGE_AFTERTOUCH:
- if (length >= 3) {
- event->set_pitch(data[1]);
- event->set_pressure(data[2]);
+ if (length >= 2 + param_position) {
+ event->set_pitch(data[param_position]);
+ event->set_pressure(data[param_position + 1]);
}
break;
case MIDI_MESSAGE_CONTROL_CHANGE:
- if (length >= 3) {
- event->set_controller_number(data[1]);
- event->set_controller_value(data[2]);
+ if (length >= 2 + param_position) {
+ event->set_controller_number(data[param_position]);
+ event->set_controller_value(data[param_position + 1]);
}
break;
case MIDI_MESSAGE_NOTE_ON:
case MIDI_MESSAGE_NOTE_OFF:
- case MIDI_MESSAGE_PITCH_BEND:
- if (length >= 3) {
- event->set_pitch(data[1]);
- event->set_velocity(data[2]);
+ if (length >= 2 + param_position) {
+ event->set_pitch(data[param_position]);
+ event->set_velocity(data[param_position + 1]);
if (event->get_message() == MIDI_MESSAGE_NOTE_ON && event->get_velocity() == 0) {
// https://www.midi.org/forum/228-writing-midi-software-send-note-off,-or-zero-velocity-note-on
@@ -83,15 +93,21 @@ void MIDIDriver::receive_input_packet(uint64_t timestamp, uint8_t *data, uint32_
}
break;
+ case MIDI_MESSAGE_PITCH_BEND:
+ if (length >= 2 + param_position) {
+ event->set_pitch((data[param_position + 1] << 7) | data[param_position]);
+ }
+ break;
+
case MIDI_MESSAGE_PROGRAM_CHANGE:
- if (length >= 2) {
- event->set_instrument(data[1]);
+ if (length >= 1 + param_position) {
+ event->set_instrument(data[param_position]);
}
break;
case MIDI_MESSAGE_CHANNEL_PRESSURE:
- if (length >= 2) {
- event->set_pressure(data[1]);
+ if (length >= 1 + param_position) {
+ event->set_pressure(data[param_position]);
}
break;
}
diff --git a/core/os/midi_driver.h b/core/os/midi_driver.h
index e0e5e2be67..33f49d19f5 100644
--- a/core/os/midi_driver.h
+++ b/core/os/midi_driver.h
@@ -41,6 +41,7 @@
class MIDIDriver {
static MIDIDriver *singleton;
+ static uint8_t last_received_message;
public:
static MIDIDriver *get_singleton();
diff --git a/core/os/os.cpp b/core/os/os.cpp
index 25889de1b3..2d61417b4f 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -572,6 +572,14 @@ bool OS::is_vsync_enabled() const {
return _use_vsync;
}
+void OS::set_vsync_via_compositor(bool p_enable) {
+ _vsync_via_compositor = p_enable;
+}
+
+bool OS::is_vsync_via_compositor_enabled() const {
+ return _vsync_via_compositor;
+}
+
OS::PowerState OS::get_power_state() {
return POWERSTATE_UNKNOWN;
}
diff --git a/core/os/os.h b/core/os/os.h
index 687ccaaba5..26db629d7c 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -60,6 +60,9 @@ class OS {
bool _allow_hidpi;
bool _allow_layered;
bool _use_vsync;
+ bool _vsync_via_compositor;
+
+ char *last_error;
void *_stack_bottom;
@@ -98,9 +101,10 @@ public:
bool maximized;
bool always_on_top;
bool use_vsync;
+ bool vsync_via_compositor;
bool layered;
float get_aspect() const { return (float)width / (float)height; }
- VideoMode(int p_width = 1024, int p_height = 600, bool p_fullscreen = false, bool p_resizable = true, bool p_borderless_window = false, bool p_maximized = false, bool p_always_on_top = false, bool p_use_vsync = false) {
+ VideoMode(int p_width = 1024, int p_height = 600, bool p_fullscreen = false, bool p_resizable = true, bool p_borderless_window = false, bool p_maximized = false, bool p_always_on_top = false, bool p_use_vsync = false, bool p_vsync_via_compositor = false) {
width = p_width;
height = p_height;
fullscreen = p_fullscreen;
@@ -109,6 +113,7 @@ public:
maximized = p_maximized;
always_on_top = p_always_on_top;
use_vsync = p_use_vsync;
+ vsync_via_compositor = p_vsync_via_compositor;
layered = false;
}
};
@@ -507,6 +512,9 @@ public:
//real, actual overridable function to switch vsync, which needs to be called from graphics thread if needed
virtual void _set_use_vsync(bool p_enable) {}
+ void set_vsync_via_compositor(bool p_enable);
+ bool is_vsync_via_compositor_enabled() const;
+
virtual OS::PowerState get_power_state();
virtual int get_power_seconds_left();
virtual int get_power_percent_left();