Ver a proveniência

Add channel config

Allow MIDI input to be filtered through MIDI channels.
feature/data-structs
TheoryOfNekomata há 2 anos
ascendente
cometimento
7454c41463
3 ficheiros alterados com 20 adições e 2 eliminações
  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 Ver ficheiro

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

+ 18
- 2
src/packages/game/input/IZ_midi.c Ver ficheiro

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

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);
if (status == IZ_MIDI_NOTE_ON) {
*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);
if (!ini_putl(
main_section_name,
"Channel",
state[player_index]->config.channel,
config_path
)) {
problem |= (1 << player_index);
}

if (!ini_putl(
main_section_name,
"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);
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);
}
}


+ 1
- 0
src/packages/game/input/IZ_midi.h Ver ficheiro

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

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



Carregando…
Cancelar
Guardar