Browse Source

Add channel config

Allow MIDI input to be filtered through MIDI channels.
feature/data-structs
TheoryOfNekomata 2 years ago
parent
commit
7454c41463
3 changed files with 20 additions and 2 deletions
  1. +1
    -0
      docs/reference/files/config.ini
  2. +18
    -2
      src/packages/game/input/IZ_midi.c
  3. +1
    -0
      src/packages/game/input/IZ_midi.h

+ 1
- 0
docs/reference/files/config.ini View File

@@ -53,4 +53,5 @@ Action7=G4
Action8="G#4" Action8="G#4"
Action9=A4 Action9=A4
[MIDIInput.0] [MIDIInput.0]
Channel=0
DeviceID=0 DeviceID=0

+ 18
- 2
src/packages/game/input/IZ_midi.c View File

@@ -63,12 +63,18 @@ uint8_t IZ_GetMIDINoteFromName(char* name) {
void IZ_HandleMIDINoteOnOffEvents(PmEvent e, IZ_MIDIInputState* state, IZ_Action* action) { void IZ_HandleMIDINoteOnOffEvents(PmEvent e, IZ_MIDIInputState* state, IZ_Action* action) {
uint32_t message = e.message; uint32_t message = e.message;
uint8_t status = message & 0xF0u; uint8_t status = message & 0xF0u;
// uint8_t channel = message & 0x0Fu;
uint8_t channel = message & 0x0Fu;
uint8_t data1 = (message >> 8) & 0xFFu; uint8_t data1 = (message >> 8) & 0xFFu;
// uint8_t data2 = (message >> 16) & 0xFFu; // uint8_t data2 = (message >> 16) & 0xFFu;


for (uint8_t i = 0; i < CONTROLS; i += 1) { for (uint8_t i = 0; i < CONTROLS; i += 1) {
if (data1 == state->config.control_mapping[i]) {
if (
data1 == state->config.control_mapping[i]
&& (
(state->config.channel < 16 && channel == state->config.channel)
|| state->config.channel >= 16
)
) {
const uint16_t bitflag = (0x1 << i); const uint16_t bitflag = (0x1 << i);
if (status == IZ_MIDI_NOTE_ON) { if (status == IZ_MIDI_NOTE_ON) {
*action |= bitflag; *action |= bitflag;
@@ -108,6 +114,15 @@ IZ_ProcedureResult IZ_SaveMIDIInputConfig(const char* config_path, IZ_MIDIInputS
} }


sprintf_s(main_section_name, 12, "MIDIInput.%d", player_index); sprintf_s(main_section_name, 12, "MIDIInput.%d", player_index);
if (!ini_putl(
main_section_name,
"Channel",
state[player_index]->config.channel,
config_path
)) {
problem |= (1 << player_index);
}

if (!ini_putl( if (!ini_putl(
main_section_name, main_section_name,
"DeviceID", "DeviceID",
@@ -142,6 +157,7 @@ void IZ_LoadMIDIInputConfig(const char* config_path, IZ_MIDIInputState(* state)[
} }


sprintf_s(main_section_name, 12, "MIDIInput.%d", player_index); sprintf_s(main_section_name, 12, "MIDIInput.%d", player_index);
state[player_index]->config.channel = ini_getl(main_section_name, "Channel", player_index, config_path);
state[player_index]->config.device_id = ini_getl(main_section_name, "DeviceID", player_index, config_path); state[player_index]->config.device_id = ini_getl(main_section_name, "DeviceID", player_index, config_path);
} }
} }


+ 1
- 0
src/packages/game/input/IZ_midi.h View File

@@ -16,6 +16,7 @@ static const uint8_t IZ_MIDI_NOTE_OFF = 0x80u;


typedef struct { typedef struct {
PmDeviceID device_id; PmDeviceID device_id;
uint8_t channel;
IZ_MIDINote control_mapping[CONTROLS]; IZ_MIDINote control_mapping[CONTROLS];
} IZ_MIDIInputConfig; } IZ_MIDIInputConfig;




Loading…
Cancel
Save