Created
March 20, 2024 06:55
-
-
Save yingshaoxo/24883f3a0495e6305a64b1902a9fb517 to your computer and use it in GitHub Desktop.
Linux MIDI input driver, protocol 1.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Linux MIDI input driver, protocol 1.0, there is no need to upgrade to protocol 2.0 | |
// Author: yingshaoxo | |
// Run it in root shell | |
// gcc main.c -o main.run | |
// ./main.run | |
#include <sys/soundcard.h> | |
#include <fcntl.h> | |
#include <unistd.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define MIDI_DEVICE "/dev/midi1" | |
//#define MIDI_DEVICE "/dev/dmmidi1" | |
//#define MIDI_DEVICE "/dev/snd/midiC1D0" | |
int main(void) { | |
unsigned char inpacket[4]; | |
// first open the sequencer device for reading. | |
int seqfd = open(MIDI_DEVICE, O_RDONLY); | |
if (seqfd == -1) { | |
printf("Error: cannot open %s\n", MIDI_DEVICE); | |
exit(1); | |
} | |
// now just wait around for MIDI bytes to arrive and print them to screen. | |
while (1) { | |
read(seqfd, &inpacket, sizeof(inpacket)); | |
if (inpacket[0] == 144) { | |
printf("Pressed: "); | |
printf("%d\n", inpacket[1]); | |
} else { | |
printf("Released: "); | |
printf("%d\n\n", inpacket[1]); | |
} | |
//printf("strongth: %d", inpacket[2]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment