Advertisement
metalx1000

GCC C code for MIDI visual output for sliders/knobs/keys

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