-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_handler.c
More file actions
executable file
·122 lines (109 loc) · 2.95 KB
/
Copy pathcommand_handler.c
File metadata and controls
executable file
·122 lines (109 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "command_handler.h"
#include "command_handler_private.h"
#include "midi/midi.h"
#include "shared/key_consts.h"
#include "shared/bus_definitions.h"
#include "shared/global.h"
#include "keyboard.h"
unsigned short midiChannelMap[MATRIXROWS * MATRIXCOLS];
unsigned short midiStatusMap[MATRIXROWS * MATRIXCOLS];
unsigned short midiControllerMap[MATRIXROWS * MATRIXCOLS];
void CMD_init(){
// Init command handler
unsigned short i;
for(i=0; i< MATRIXROWS * MATRIXCOLS; i++){
delay_ms(50);
midiChannelMap[i] = 0;
midiStatusMap[i] = 0x90; //note on
midiControllerMap[i] = 60 + i;
}
}
/**
* value should be between 0 and 127
*/
void CMD_generalEventDispatcher(char key, unsigned short value){
PORTC = value;
if(GLOBAL_mode == MODE_LEARN){
if(MIDI_messageReady){
midiChannelMap[key] = MIDI_lastChannel;
midiStatusMap[key] = MIDI_lastStatus;
midiControllerMap[key] = MIDI_lastData1;
MIDI_messageReady = 0;
SYSTEM_LED_LEARN = 0;
delay_ms(500);
SYSTEM_LED_LEARN = 1;
}
} else if(GLOBAL_mode == MODE_PLAY){
PORTE.F1 = 1;
MIDI_sendMidiMessage(
midiChannelMap[key],
midiStatusMap[key],
midiControllerMap[key],
value
);
delay_ms(10);
PORTE.F1 = 0;
MIDI_sendMidiMessage(
midiChannelMap[key],
midiStatusMap[key],
midiControllerMap[key],
0
);
}
}
void CMD_keyEventDispatcher(char key, unsigned short keydirection){
// Todo: reintroduce key repeat if necessary
// Todo: reintroduce shift if necessary
if(keydirection == KEYDIR_DOWN){
CMD_dispatchKeyDown(key);
} else {
CMD_dispatchKeyUp(key);
}
}
void CMD_dispatchKeyDown(char key){
if(GLOBAL_mode == MODE_LEARN){
if(MIDI_messageReady){
midiChannelMap[key] = MIDI_lastChannel;
midiStatusMap[key] = MIDI_lastStatus;
midiControllerMap[key] = MIDI_lastData1;
MIDI_messageReady = 0;
SYSTEM_LED_LEARN = 0;
delay_ms(500);
SYSTEM_LED_LEARN = 1;
}
} else if(GLOBAL_mode == MODE_PLAY){
MIDI_sendMidiMessage(
midiChannelMap[key],
midiStatusMap[key],
midiControllerMap[key],
64
);
}
}
void CMD_dispatchKeyUp(char key){
if(GLOBAL_mode == MODE_LEARN){
//insert learning code here if we decide to support different up/down statuses.
} else if(GLOBAL_mode == MODE_PLAY){
MIDI_sendMidiMessage(
midiChannelMap[key],
midiStatusMap[key],
midiControllerMap[key],
0
);
}
}
void CMD_systemKeyEventDispatcher(char key, unsigned short keydirection){
switch(key){
case 0: // mode toggle
if(keydirection == KEYDIR_DOWN){
if(GLOBAL_mode == MODE_PLAY){
GLOBAL_mode = MODE_LEARN;
SYSTEM_LED_LEARN = 1;
} else {
GLOBAL_mode = MODE_PLAY;
SYSTEM_LED_LEARN = 0;
}
}
break;
}
}