Advertisement
metalx1000

MIDI basic read gcc

Oct 24th, 2017
642
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.31 KB | None | 0 0
  1. /*
  2.  * Copyright (c) 2017 Kris Occhipint.
  3.  * http://filmsbykris.com
  4.  *
  5.  * This program is free software: you can redistribute it and/or modify  
  6.  * it under the terms of the GNU General Public License as published by  
  7.  * the Free Software Foundation, version 3.
  8.  *
  9.  * This program is distributed in the hope that it will be useful, but
  10.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12.  * General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16.  */
  17. #include <sys/soundcard.h>
  18. #include <fcntl.h>
  19. #include <unistd.h>
  20. #include <stdio.h>
  21.  
  22. //#define  DEVICE  "/dev/sequencer"
  23. #define  DEVICE  "/dev/midi4"
  24.  
  25.  
  26. int main(void) {
  27.    unsigned char input[4];
  28.  
  29.    // open the midi device for reading.
  30.    int seqfd = open(DEVICE, O_RDONLY);
  31.    if (seqfd == -1) {
  32.       printf("Error: cannot open %s\n", DEVICE);
  33.       return 1;
  34.    }
  35.  
  36.    // wait for MIDI input and print it to the screen.
  37.    while (1) {
  38.       read(seqfd, &input, sizeof(input));
  39.       //print what key/knob/slider is being pressed and at what value
  40.       printf("MIDI byte: %d - %d\n", input[1], input[2]);
  41.    }
  42.      
  43.    return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement