what's wrong with this code??? i'm trying to play an array on notes thru midi....only new to this subject....this code compiles but crashes when i run the .exe file....think i remember someone saying something about running printf and scanf with midi although i can't for the life of me remember what it was... if anybody has information they could share would really appreciate it . cheers
runing the code with: gcc -o test test.c -I. -L. -lportmidi -lwinmm
Code:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <portmidi.h>
#define MD_NOTEON 0x90
#define MD_NOTEOFF 0x80
#define MD_PRG 0xC0
#define SBYTE(mess,chan) mess | chan
int main()
{
int array [3][3];
int a [3]={0,0,0};
int b [3]={0,0,0};
{
int play(int array[3][3]);
{
int cnt,i,dev;
PmError retval;
const PmDeviceInfo *info;
PortMidiStream *mstream;
Pm_Initialize();
if(cnt = Pm_CountDevices())
{
for(i=0; i < cnt; i++)
{
info = Pm_GetDeviceInfo(i);
if(info->output)
printf("%d: %s \n", i, info->name);
}
printf("choose device: ");
scanf("%d", &dev);
Pt_Start(1, NULL, NULL);
retval = Pm_OpenOutput(&mstream, dev,
NULL,512,NULL,NULL,0);
if(retval != pmNoError)
printf("error: %s \n", Pm_GetErrorText(retval));
else
{
int a,b,
fine = array [a][b];
char chan = 0;
int prg = 4;
long time = 0;
if(fine == 0)
{
Pm_WriteShort(mstream, 0,
Pm_Message(SBYTE(MD_PRG,chan), prg, 0));
time = Pt_Time(NULL);
Pm_WriteShort(mstream, 0,
Pm_Message(SBYTE(MD_NOTEON,chan), 60, 120));
while(Pt_Time(NULL) - time < 1000);
Pm_WriteShort(mstream, 0,
Pm_Message(SBYTE(MD_NOTEOFF,chan), 60, 120));
}
}
Pm_Close(mstream);
}
else printf("No available output devices\n");
Pm_Terminate();
return 0;
}
}
}