Midi Instruments

Posted By: rojart

Midi Instruments - 04/22/09 03:40

Hi,
Here an example for playing all midi Instruments, that I use it for my contest entry Vaders, maybe you like it.

P - play all midi Instruments
Esc - exit

Any comments are welcome.

Code:
  //Created by rojart 2009
#include <acknex.h>
#define API(name,lib)  #define PRAGMA_API name;lib!name
#define DECLARE_HANDLE(name) typedef HANDLE name
#define CALLBACK_NULL 0x0

DECLARE_HANDLE(HMIDIOUT);
HMIDIOUT hMidiout;

DWORD __stdcall midiOutOpen(DWORD*,DWORD,DWORD,DWORD,DWORD);
DWORD __stdcall midiOutShortMsg(DWORD,DWORD);
DWORD __stdcall midiOutReset(DWORD);
DWORD __stdcall midiOutClose(DWORD);

API(midiOutOpen,winmm)
API(midiOutShortMsg,winmm)
API(midiOutReset,winmm)
API(midiOutClose,winmm)

int midiport = 0;

int on_p_event()
{
	int i; BYTE octave = 60; BYTE volume = 127;
	
	for(i=0;i<=127;i++)
	{
		midiOutShortMsg(hMidiout, (volume << 16) | (i          << 8) | 0xC0);wait(1);  // Instrument
		midiOutShortMsg(hMidiout, (volume << 16) | (octave     << 8) | 0x90);wait(-1); // note/octave on
		midiOutShortMsg(hMidiout, (volume << 16) | (octave     << 8) | 0x80);wait(1);  // note off
	}
}

void main()
{
	midiOutOpen(&hMidiout, midiport, 0, 0, CALLBACK_NULL);
}

void on_esc_event()
{
	wait(1);
	midiOutReset(hMidiout);wait(1);
	midiOutClose(hMidiout);wait(1);
	sys_exit(NULL);
}

Posted By: Anonymous

Re: Midi Instruments - 04/22/09 06:17

If works it's a great contribution!
Thanx.
Posted By: rojart

Re: Midi Instruments - 04/22/09 23:25

Thank you for the kind words!
The same but plays only drums at channel 10 (0x9)

P - play all drums
Esc - Exit

Code:
//Created by rojart 2009
#include <acknex.h>
#define API(name,lib)  #define PRAGMA_API name;lib!name
#define DECLARE_HANDLE(name) typedef HANDLE name
#define MIDI_MAPPER -1
#define CALLBACK_NULL 0x0

DECLARE_HANDLE(HMIDIOUT);
HMIDIOUT hMidiout;

DWORD __stdcall midiOutOpen(DWORD*,DWORD,DWORD,DWORD,DWORD);
DWORD __stdcall midiOutShortMsg(DWORD,DWORD);
DWORD __stdcall midiOutReset(DWORD);
DWORD __stdcall midiOutClose(DWORD);

API(midiOutOpen,winmm)
API(midiOutShortMsg,winmm)
API(midiOutReset,winmm)
API(midiOutClose,winmm)

int midiport = 0;

int on_p_event()
{
	int i; BYTE volume = 127;
	
	for(i=27;i<=89;i++)
	{
		midiOutShortMsg(hMidiout, (volume << 16) | (i << 8) | 0xC9);wait(1);    // Drum Sounds
		midiOutShortMsg(hMidiout, (volume << 16) | (i << 8) | 0x99);wait(-0.5); // Drum on
		midiOutShortMsg(hMidiout, (volume << 16) | (i << 8) | 0x89);wait(1);    // Drum off
	}
}

void main()
{
	//midiOutOpen(&hMidiout, MIDI_MAPPER, 0, 0, 0);
	//UINT result = midiOutOpen(&hMidiout, MIDI_MAPPER, 0, 0, 0);
	//if(result != MMSYSERR_NOERROR) printf("No MIDI output devices!",0);
	midiOutOpen(&hMidiout, midiport, 0, 0, CALLBACK_NULL);
}

void on_esc_event()
{
	wait(1);
	midiOutReset(hMidiout);wait(1);
	midiOutClose(hMidiout);wait(1);
	sys_exit(NULL);
}

Posted By: Quad

Re: Midi Instruments - 04/22/09 23:50

awesome laugh you should have contributed this before the no-resources contest, most could make use of this.
Posted By: rojart

Re: Midi Instruments - 04/23/09 00:33

Thanks and yes, youŽre right, I forgot to add on one Panel from Vaders entry, but have already used as sound for it. wink
Posted By: Jaxas

Re: Midi Instruments - 04/24/09 08:51

realy good contribution smile must have in my example collection smile
Posted By: Shadow969

Re: Midi Instruments - 04/24/09 15:23

nice one! thumbs up smile
Posted By: oliver2s

Re: Midi Instruments - 04/25/09 14:15

Really nice. Thank you smile
Posted By: KiwiBoy

Re: Midi Instruments - 04/25/09 20:35

How would I use this?
Been looking for a way to make a synthisiser of sorts so thought maybe this could be an option.
Posted By: rojart

Re: Midi Instruments - 04/28/09 01:14

Thank you all for the kind words!
After Spring contest 2009 IŽll describe all the Midi functions with an example as a simple synthesiser
Posted By: KiwiBoy

Re: Midi Instruments - 04/28/09 02:05

Awesome rojart, would really like that very much.
© 2024 lite-C Forums