- Joined
- Mar 19, 2024
- Messages
- 3
- Reaction score
- 1
// 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;
}
// 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;
}