Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
292 lines (255 sloc) 6.22 KB
/* -----------------------------------------------------------------------------
BrainBay Version 1.7, GPL 2003-2010, contact:
MODULE: MIDI.CPP: contains error-reporting and -handling functions
midi_open_port: opens a specified Midi Output-Port
init_midi: inits Instrument/Controller Names, opens all available midi-out- Ports
midi_Instrument: Selects the midi-instrument for a given channel
midi_ControlChange: sends a control-change - message on a given channel
midi_NoteOn: plays a tone with given hieght, volume on a given channel
midi_NoteOff: mutes a tone
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; See the
GNU General Public License for more details.
#include "brainBay.h"
#include "ob_midi.h"
char midi_instnames[256][30]= {
{"Acoustic Grand Piano"},
{"Bright Acoustic Piano"},
{"Electric Grand Piano"},
{"Honky-tonk Piano"},
{"Electric Piano 1"},
{"Electric Piano 2"},
{"Music Box"},
{"Tubular Bells"},
{"Drawbar Organ"},
{"Percussive Organ"},
{"Rock Organ"},
{"Church Organ"},
{"Reed Organ"},
{"Tango Accordion"},
{"Acoustic Guitar (Nylon)"},
{"Acoustic Guitar (Steel)"},
{"Electric Guitar (Jazz)"},
{"Electric Guitar (Clean)"},
{"Electric Guitar (Muted)"},
{"Overdriven Guitar"},
{"Distortion Guitar"},
{"Guitar Harmonics"},
{"Acoustic bass"},
{"Electric Bass (Finger)"},
{"Electric Bass (Pick)"},
{"Fretless Bass"},
{"Slap Bass 1"},
{"Slap Bass 2"},
{"Synth Bass 1"},
{"Synth Bass 2"},
{"Tremolo Strings"},
{"Pizzicato Strings"},
{"Orchestral Harp"},
{"String Ensemble 1"},
{"String Ensemble 2"},
{"Synth Strings 1"},
{"Synth Strings 2"},
{"Choir Aahs"},
{"Voice Oohs"},
{"Synth Voice"},
{"Orchestra Hit"},
{"Muted Trumpet"},
{"French Horn"},
{"Brass Section"},
{"Synth Brass 1"},
{"Synth Brass 2"},
{"Soprano Sax"},
{"Alto Sax"},
{"Tenor Sax"},
{"Baritone Sax"},
{"English Horn"},
{"Pan Flute"},
{"Blown Bottle"},
{"Lead 1 (Square)"},
{"Lead 2 (Sawtooth)"},
{"Lead 3 (Calliope)"},
{"Lead 4 (Chiff)"},
{"Lead 5 (Charang)"},
{"Lead 6 (Voice)"},
{"Lead 7 (Fifths)"},
{"Lead 8 (Bass + Lead)"},
{"Pad 1 (New Age)"},
{"Pad 2 (Warm)"},
{"Pad 3 (Polysynth)"},
{"Pad 4 (Choir)"},
{"Pad 5 (Bowed)"},
{"Pad 6 (Metallic)"},
{"Pad 7 (Halo)"},
{"Pad 8 (Sweep)"},
{"FX 1 (Rain)"},
{"FX 2 (Soundtrack)"},
{"FX 3 (Crystal)"},
{"FX 4 (Atmosphere)"},
{"FX 5 (Brightness)"},
{"FX 6 (Goblins)"},
{"FX 7 (Echoes)"},
{"FX 8 (Sci-fi)"},
{"Tinkle Bell"},
{"Steel Drums"},
{"Wood Block"},
{"Taiko Drum"},
{"Melodic Drum"},
{"Synth Drum"},
{"Reverse Cymbal"},
{"Guitar Fret Noise"},
{"Breath Noise"},
{"Bird Tweet"},
{"Telephone Ring"},
int midi_open_port(HMIDIOUT * midiout, int portnum)
if (midiout) midiOutClose(* midiout);
if (midiOutOpen(midiout,portnum-1,0,0,CALLBACK_NULL)==MMSYSERR_NOERROR)
return TRUE;
write_logfile("could not open midi port");
return FALSE;
void mute_all_midi(void)
int i,t;
if (objects[i]->type==OB_MIDI)
MIDIOBJ * st= (MIDIOBJ *) objects[i];
if (MIDIPORTS[st->port].midiout)
midi_ControlChange(&(MIDIPORTS[st->port].midiout), st->midichn,123, 0);
midi_ControlChange(&(MIDIPORTS[st->port].midiout), st->midichn,120, 0);
for (t=0;t<MAX_MIDITONES;t++) st->tonebuffer[t]=0;
void init_midi (void)
char sztemp[50];
for (int t=128; t<255; t++)
wsprintf(sztemp,"Controller Nr.%d",t-127);
for (int t = -1; t < (int) midiOutGetNumDevs(); t++)
// for (unsigned int t = 0; t < midiOutGetNumDevs(); t++)
midiOutGetDevCaps(t, &(ocaps), sizeof (MIDIOUTCAPS));
strcpy(MIDIPORTS[GLOBAL.midiports].portname, ocaps.szPname ) ;
int get_listed_midiport(int num)
int i,c;
for (i=0;i<GLOBAL.midiports;i++)
if (MIDIPORTS[i].midiout) c++;
if (c==num) return(i);
int get_opened_midiport(int num)
int i,c;
for (i=0;i<=num;i++)
if (MIDIPORTS[i].midiout) c++;
void midi_Instrument(HMIDIOUT * midiout, int chn, int inst)
if (inst<128) midiOutShortMsg(*midiout, 256*inst+191+chn);
// 1-127: Instruments for noteOn, 128 - 255: Controller numbers
void midi_ControlChange(HMIDIOUT * midiout, int chn, int cont, int val)
void midi_NoteOn(HMIDIOUT * midiout, int chn, int note, int vol)
void midi_NoteOff(HMIDIOUT * midiout, int chn, int note)
void midi_PitchRange(HMIDIOUT * midiout, int chn, int pitchrange)
/* 'B0 65 00 Controller/chan 0, RPN coarse (101), Pitch Bend Range
'B0 64 00 Controller/chan 0, RPN fine (100), Pitch Bend Range
'B0 06 02 Controller/chan 0, Data Entry coarse, +/- 2 semitones
'B0 26 04 Controller/chan 0, Data Entry fine, +/- 4 cents
midi_ControlChange(midiout, chn,101, 0);
midi_ControlChange(midiout, chn,100, 0);
midi_ControlChange(midiout, chn,6, pitchrange);
midi_ControlChange(midiout, chn,38, 0);
void midi_Vol(HMIDIOUT * midiout, int chn, int vol)
midi_ControlChange(midiout, chn,7, vol);
void midi_Pitch(HMIDIOUT * midiout, int chn, int wheel)
int wl,wh;
midiOutShortMsg(*midiout,65536*wh+256*wl+223+chn); //
void midi_Message(HMIDIOUT * midiout, int status)
midiOutShortMsg(*midiout, status*255);
Jump to Line
Something went wrong with that request. Please try again.