midi programming

This is a discussion on midi programming within the C Programming forums, part of the General Programming Boards category; what's wrong with this code??? i'm trying to play an array on notes thru midi....only new to this subject....this code ...

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    13

    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

    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;
    		}
    	}
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,668
    > 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
    Try
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 10: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 Cprogramming.com
    Replies: 7
    Last Post: 10-27-2002, 10:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21