Thread: midi programming

  1. #1
    Registered User
    Join Date
    Dec 2008

    midi programming

    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

    #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;
    			if(cnt = Pm_CountDevices())
    				for(i=0; i < cnt; i++)
    					info = Pm_GetDeviceInfo(i);
    					printf("%d: %s \n", i, info->name);
    				printf("choose device: ");
    				scanf("%d", &dev);
    				Pt_Start(1, NULL, NULL);
    				retval = Pm_OpenOutput(&mstream, dev,
    				if(retval != pmNoError)
    				printf("error: %s \n", Pm_GetErrorText(retval));
    					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));
    			else printf("No available output devices\n");
    			return 0;

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > int array [3][3];
    This is uninitialised

    > int a [3]
    This array is masked by a variable with the same name in an inner scope.
    Ditto for b

    > fine = array [a][b];
    Your a and b are uninitialised here as well, so you just index garbage.

    > gcc -o test test.c -I. -L. -lportmidi -lwinmm
    gcc -W -Wall -o test test.c -I. -L. -lportmidi -lwinmm
    Then fix what it complains about.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to play midi music from resource without directX
    By alaphate in forum Windows Programming
    Replies: 0
    Last Post: 03-12-2009, 08:49 AM
  2. Guitar Hero ALSA MIDI output
    By redxine in forum Linux Programming
    Replies: 0
    Last Post: 01-24-2009, 11:03 PM
  3. Intercept the MIDI Out
    By MattMik in forum C++ Programming
    Replies: 2
    Last Post: 10-18-2007, 02:05 AM
  4. Playing a Midi. (win32 console) (MSVC++)
    By knave in forum Windows Programming
    Replies: 3
    Last Post: 05-17-2003, 10:40 AM
  5. Converting from MIDI to WAV/DLLs
    By sean in forum A Brief History of
    Replies: 7
    Last Post: 10-27-2002, 11:31 AM