view c/portmidi/main.cc @ 163:f0a347cd9c6a pairPro

fix subsetconstraction.cc
author masa
date Fri, 18 Dec 2015 19:44:07 +0900
parents d6fd8aaaa358
children
line wrap: on
line source

#include <iostream>
#include "portmidi.h"
#include "porttime.h"
#include <time.h>
#include <stdlib.h>

#define TIME_PROC ((long (*)(void *)) Pt_Time)

using namespace std;

    PmStream * midi;
    char line[80];
    PmEvent buffer[5];
    void process_midi(PtTimestamp timestamp, void *userData);

int main(int argc, char *argv[])
{
    //pt_start must be called before initialising midi
    Pt_Start(2000, &process_midi, 0);
    Pm_Initialize();
    int device = 0;//microsoft midi mapper...
    Pm_OpenOutput(&midi,device,NULL,0,NULL,NULL,10);
    /*calling callback function once. When I called Pt_start
    it waits until 'resolution' millisecs have passed before
    start, hence I call the callback function once beforehand */
    process_midi(0, NULL);
    cin.get();
    //wiat for user input and then stop midi timer callback function...
    Pt_Stop();
    Pm_Close(midi);
    printf("done closing and terminating...\n");
    Pm_Terminate();
}

void process_midi(PtTimestamp timestamp, void *userData)
{
    buffer[0].timestamp = timestamp+0;
    buffer[0].message = Pm_Message(0x90, 60, 100);
    buffer[1].timestamp = timestamp+1000;
    buffer[1].message = Pm_Message(0x90, 60, 0);
    buffer[2].timestamp = timestamp+1000;
    buffer[2].message = Pm_Message(0x90, 64, 100);
    buffer[3].timestamp = timestamp+2000;
    buffer[3].message = Pm_Message(0x90, 64, 0);
    Pm_Write(midi, buffer, 4);
}