notes/GCC C code for running a command when MIDI key pressed-ZYU1iGh8.sh
/* 
 * Copyright (c) 2017 Kris Occhipint.
 * http://filmsbykris.com 
 *
 * Runs commands when keys are pressed on MIDI device
 *
 * This program is free software: you can redistribute it and/or modify  
 * it under the terms of the GNU General Public License as published by  
 * the Free Software Foundation, version 3.
 *
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License 
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
#include <stdlib.h>
#include <sys/soundcard.h>
#include <fcntl.h>
#include <unistd.h>

#include <stdio.h>


//#define  DEVICE  "/dev/sequencer"
#define  DEVICE  "/dev/midi4"


int main(void) {
  unsigned char input[4];


  // open the midi device for reading.
  int seqfd = open(DEVICE, O_RDONLY);
  if (seqfd == -1) {
    printf("Error: cannot open %s\n", DEVICE);
    return 1;
  } 

  // wait for MIDI input and then run a program when keys are pressed.
  while (1) {
    read(seqfd, &input, sizeof(input));
    //if value of input is greater then 0
    //this is so it doesn't run the programm again 
    //when key is released
    if(input[2] > 0){
      //run set programs with defined key is pressed
      if(input[1] == 50){
        system("htop");
      }else if(input[1] == 52){
        system("ifconfig");
      }else if(input[1] == 53){
        system("zenity --info --text 'Hello World!'");
      }else if(input[1] == 55){
        //Sends keys to current focused program
        //xautomation must be installed
        //sudo apt install xautomation
        system("xte 'str This is a TEST...Hello World!'");
      }
    }
  }

  return 0;
}

syntax highlighted by Code2HTML, v. 0.9.1