Forum archive
KEN: Midi + keyboard
- Hello Ken
I recently bought a midi adapter for my piano and want to know which software you use for recording. Do you use staff recording as well?
I tried note worty software for that but it has some limitations I dont really like like the predefined rythm for example.
ciao
Sebastian - I don't know what you mean by "staff recording". Maybe that's because I don't use commercial MIDI software. I always write my own MIDI sequencers. If you're an experienced programmer, it's really not hard. Since I know you're a Windows programmer, I'll give you some sample code to help you get started:
HMIDIIN gmi;
void CALLBACK MidiInProc (HMIDIIN hmi, UINT wmsg, DWORD dwinst, DWORD dwp1, DWORD dwp2)
{
int frq, vol;
switch(wmsg)
{
case MIM_DATA:
switch (dwp1&255)
{
case 0x80: dwp1 &= 0xffff; //no break intentional
case 0x90: frq = (dwp1>>8)&255;; vol = (dwp1>>16)&255; handle(frq,vol); break;
}
}
}
void initmidiin ()
{ midiInOpen(&gmi,0,(DWORD)MidiInProc,0,CALLBACK_FUNCTION); midiInStart(gmi); }
void uninitmidiin ()
{ midiInStop(gmi); midiInReset(gmi); midiInClose(gmi); }
...
initmidiin();
...
(main loop)
...
uninitmidiin();
This code simply reads the keys that the piano is sending to the computer. Later, you might want to use the MidiOut* functions to control things like: turning off all notes at program open/close, and turning on/off local control. I did not include this code since this is just to get you started.
If you write your own music synthesizer, I would recommend using an ASIO driver for low latency playback. DirectSound's latency is usually too high for realtime recording/listening. The only thing stopping me from using ASIO all the time is its behavior during crashes... : / - by staff recording I mean that a program automatically writes notes in the staff.
Thanks for the code but I dont have time to do that now. When I have time I'll write a midi synethesizer for sure, but for now time is too limited.
Since you dont work with midi software try this:
http://www.noteworthysoftware.com/
it might be interesting for you.
Sebastian - Thank you for the code sample Ken! :)
Could you please do the similar code sample, which
reads the keys that the piano is sending to the computer but for DOS to help to get started?
Thanks in advance. :) - I'm too nice.
//MIDITYPE:
//0 = MPU401 at 0x330
//1 = Pro Audio Spectrum MIDI
//2 = Sound Blaster MIDI at 0x22x
#define MIDITYPE 2 //Choose your type!
int getdata ()
{
int i;
#if (MIDITYPE == 0)
for(i=256;i;i--) if (!(inp(0x331)&128)) return(inp(0x330));
#elif (MIDITYPE == 1)
for(i=256;i;i--) if (inp(0x1b88)&4) return(inp(0x178a));
#elif (MIDITYPE == 2)
if (inp(0x22e)&128) return(inp(0x22a));
#endif
return(-1);
}
int putdata (int d)
{
int i;
#if (MIDITYPE == 0)
for(i=256;i;i--) if (!(inp(0x331)&64)) { outp(0x330,d); return(d); }
#elif (MIDITYPE == 1)
for(i=256;i;i--) if ((inp(0x1b89)&0xf0)!=0x10) { outp(0x178a,d); return(d); }
#elif (MIDITYPE == 2)
for(i=256;i;i--) if (!(inp(0x22c)&128)) { outp(0x22c,d); return(d); }
#endif
return(-1);
}
void putcmd (int d)
{
int i;
#if (MIDITYPE == 0)
for(i=256;i;i--) if (!(inp(0x331)&64)) break;
outp(0x331,d);
for(i=256;i;i--) if (!(getdata()&0xfe)) break;
#elif (MIDITYPE == 1)
if (d == 0x7f) outp(0x178b,1);
#elif (MIDITYPE == 2)
outp(0x226,1); for(i=256;i;i--); outp(0x226,0); //Reset SB
while (!(inp(0x22e)&128)); inp(0x22a);
if (d != 0x7f) return;
for(i=32767;i;i--) if (!(inp(0x22c)&128)) { outp(0x22c,0x34); break; }
#endif
}
putcmd(0x3f); //open
(main loop)
{
? = getdata();
putdata(?);
...
}
putcmd(0xff); //close - WOW!
Thank you! Thank you! Thank you! :)