Skip to content

Commit cdc9ef1

Browse files
committed
add NoteOff to keyjazz
1 parent 6d50e07 commit cdc9ef1

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

input.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void close_game_controllers() {
9191
}
9292

9393
static input_msg_s handle_keyjazz(SDL_Event *event, uint8_t keyvalue) {
94-
input_msg_s key = {keyjazz, keyvalue};
94+
input_msg_s key = {keyjazz, keyvalue, event->type};
9595
switch (event->key.keysym.scancode) {
9696
case SDL_SCANCODE_Z:
9797
key.value = keyjazz_base_octave * 12;

input.h

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ typedef enum special_messages_t {
3232
typedef struct input_msg_s {
3333
input_type_t type;
3434
uint8_t value;
35+
uint32_t eventType;
3536
} input_msg_s;
3637

3738
void close_game_controllers();

main.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ int main(int argc, char *argv[]) {
7272
#endif
7373

7474
uint8_t prev_input = 0;
75+
uint8_t prev_note = 0;
7576

7677
// main loop
7778
while (run) {
@@ -87,14 +88,15 @@ int main(int argc, char *argv[]) {
8788
}
8889
break;
8990
case keyjazz:
90-
if (input.value != prev_input) {
91-
prev_input = input.value;
92-
if (input.value != 0) {
91+
if (input.value != 0) {
92+
if (input.eventType == SDL_KEYDOWN && input.value != prev_input) {
9393
send_msg_keyjazz(port, input.value, 0xFF);
94-
} else {
95-
send_msg_keyjazz(port, 0, 0);
94+
prev_note = input.value;
95+
} else if (input.eventType == SDL_KEYUP && input.value == prev_note) {
96+
send_msg_keyjazz(port, 0xFF, 0);
9697
}
9798
}
99+
prev_input = input.value;
98100
break;
99101
case special:
100102
if (input.value != prev_input) {

0 commit comments

Comments
 (0)