
'notes

/*
% C    0   00  0C  18  24  30  3C  48  54  60  6C  78  'middle C note 60 (0X3C)
% C#   1   01  0D  19  25  31  3D  49  55  61  6D  79
% D    2   02  0E  1A  26  32  3E  4A  56  62  6E  7A
% D#   3   03  0F  1B  27  33  3F  4B  57  63  6F  7B
% E    4   04  10  1C  28  34  40  4C  58  64  70  7B
% F    5   05  11  1D  29  35  41  4D  59  65  71  7C
% F#   6   06  12  1E  2A  36  42  4E  5A  66  72  7D
% G    7   07  13  1F  2B  37  43  4F  5B  67  73  7E
% G#   8   08  14  20  2C  38  44  50  5C  68  74  7F
% A    9   09  15  21  2D  39  45  51  5D  69  75
% A#  10   0A  16  22  2E  3A  46  52  5E  6A  76
% B   11   0B  17  23  2F  3B  47  53  5F  6B  77
*/


'octaves 0..10 (*12)

'middle C=60 (261.626Hz)
'A above middle C = 69 (440 Hz)
'standard tuning frequencies
'f=pow(2,d-69)*440


'Channels 0..15 (09 for percussion)

'Programs (instruments)

% AcousticGrandPiano   0  '00
% BrightAcousticPiano  1  '01
% ElectricGrandPiano   2  '02
% HonkyTonkPiano       3  '03
% RhodesPiano          4  '04
% ChorusedPiano        5  '05
% Harpsichord          6  '06
% Clarinet             7  '07
% Celesta              8  '08
% Glockenspiel         9  '09
% MusicBox            10  '0A
% Vibraphone          11  '0B
% Marimba             12  '0C
% Xylophone           13  '0D
% TubularBells        14  '0E
% Dulcimer            15  '0F
% HammondOrgan        16  '10
% PercussiveOrgan     17  '11
% RockOrgan           18  '12
% ChurchOrgan         19  '13
% ReedOrgan           20  '14
% Accordion           21  '15
% Harmonica           22  '16
% TangoAccordion      23  '17
% AcousticGuitarNylon 24  '18
% AcousticGuitarSteel 25  '19
% ElectricGuitarJazz  26  '1A
% ElectricGuitarClean 27  '1B
% ElectricGuitarMuted 28  '1C
% OverdrivenGuitar    29  '1D
% DistortionGuitar    30  '1E
% GuitarHarmonics     31  '1F
% AcousticBass        32  '20
% ElectricBassFinger  33  '21
% ElectricBassPick    34  '22
% FretlessBass        35  '23
% SlapBass1           36  '24
% SlapBass2           37  '25
% SynthBass1          38  '26
% SynthBass2          39  '27
% Violin              40  '28
% Viola               41  '29
% Cello               42  '2A
% ContraBass          43  '2B
% TremoloStrings      44  '2C
% PizzicatoStrings    45  '2D
% OrchestralHarp      46  '2E
% Timpani             47  '2F
% StringEnsemble1     48  '30
% StringEnsemble2     49  '31
% SynthStrings1       50  '32
% SynthStrings2       51  '33
% ChoirAahs           52  '34
% VoiceOohs           53  '35
% SynthVoice          54  '36
% OrchestraHit        55  '37
% Trumpet             56  '38
% Trombone            57  '39
% Tuba                58  '3A
% MutedTrumpet        59  '3B
% FrenchHorn          60  '3C
% BrassSection        61  '3D
% SynthBrass1         62  '3E
% SynthBrass2         63  '3F
% SopranoSaxaphone    64  '40
% AltoSaxophone       65  '41
% TenorSaxophone      66  '42
% BaritoneSaxophone   67  '43
% Oboe                68  '44
% EnglishHorn         69  '45
% Basson              70  '46
% Clarinet            71  '47
% Piccolo             72  '48
% Flute               73  '49
% Recorder            74  '4A
% PanFlute            75  '4B
% BottleBlow          76  '4C
% Shakuchi            77  '4D
% Whistle             78  '4E
% Ocarina             79  '4F
% Lead1Square         80  '50
% Lead2Sawtooth       81  '51
% Lead3CalliopeLead   82  '52
% Lead4ChiffLead      83  '53
% Lead5Charang        84  '54
% Lead6Voice          85  '55
% Lead7Fifths         86  '56
% Lead8BassPlusLead   87  '57
% Pad1NewAge          88  '58
% Pad2Warm            89  '59
% Pad3Polysynth       90  '5A
% Pad4Choir           91  '5B
% Pad5Bowed           92  '5C
% Pad6Metallic        93  '5D
% Pad7Halo            94  '5E
% Pad8Sweep           95  '5F
% FX1Rain             96  '60
% FX2SoundTrack       97  '61
% FX3Crystal          98  '62
% FX4Atmosphere       99  '63
% FX5Brightness      100  '64
% FX6Goblins         101  '65
% FX7Echoes          102  '66
% FX8SciFi           103  '67
% Sitar              104  '68
% Banjo              105  '69
% Shamisen           106  '6A
% Koto               107  '6B
% Kalimba            108  '6C
% Bagpipe            109  '6D
% Fiddle             110  '6E
% Shanai             111  '6F
% SteelsDrums        112  '70
% Agogo              113  '71
% Steeldrum          114  '72
% Woodblock          115  '73
% TaikoDrum          116  '74
% MelodicTom         117  '75
% SynthDrum          118  '76
% ReverseCymbal      119  '77
% GuitarFretNoise    120  '78
% BreathNoise        121  '79
% Seashore           122  '7A
% BirdTweet          123  '7B
% TelephoneRing      124  '7C
% Helicopter         125  '7D
% Applause           126  '7E
% GunShot            127  '7F

'Percussion Key Assignments (Channel 09)

% AcousticBassDrum    35  '23
% BassDrum1           36  '24
% SideStick           37  '25
% AcousticSnare       38  '26
% Handclap            39  '27
% ElectricSnare       40  '28
% LowFloorTom         41  '29
% ClosedHighHat       42  '2A
% HighFloorTom        43  '2B
% PedalHighHat        44  '2C
% LowTom              45  '2D
% HighHat             46  '2E
% LowMidTom           47  '2F
% HighMidTom          48  '30
% CrashCymbal         49  '31
% HighTom             50  '32
% RideCymbal1         51  '33
% ChineseCymbal       52  '34
% RideBell1           53  '35
% Tambourine          54  '36
% SplashCymbal        55  '37
% CowBell             56  '38
% CrashCymbal2        57  '39
% VibraSlap           58  '3A
% RideCymbel2         59  '3B
% HighBongo           60  '3C
% LowBongo            61  '3D
% MuteHighConga       62  '3E
% HighConga           63  '3F
% LowConga            64  '40
% HighTimbale         65  '41
% LowTimbale          66  '42
% HighAgogo           67  '43
% LowAgogo            68  '44
% Cabasa              69  '45
% Maracas             70  '46
% ShortWistle         71  '47
% LongWistle          72  '48
% ShortGuiro          73  '49
% LongGuiro           74  '4A
% Claves              75  '4B
% HighWoodBlock       76  '4C
% LowWoodBlock        77  '4D
% MuteCuica           78  '4E
% Cuica               79  '4F
% MuteTriangle        80  '50
% Triangle            81  '51

'Controllers

% BankSelect              0  '00
% ModulationWheel         1  '01
% BreathController        2  '02
% ContinuousController3   3  '03
% FootController          4  '04
% PortamentoTime          5  '05
% DataEntry               6  '06
% MainVolume              7  '07
% Balance                 8  '08
% ContinuousController9   9  '09
% Pan                    10  '0A
% Expression             11  '0B
% ContinuousController12 12  '0C
% ContinuousController13 13  '0D
% ContinuousController14 14  '0E
% ContinuousController15 15  '0F
% GeneralController1     16  '10
% GeneralController2     17  '11
% GeneralController3     18  '12
% GeneralController4     19  '13
% ContinuousController20 20  '14
% ContinuousController21 21  '15
% ContinuousController22 22  '16
% ContinuousController23 23  '17
% ContinuousController24 24  '18
% ContinuousController25 25  '19
% ContinuousController26 26  '1A
% ContinuousController27 27  '1B
% ContinuousController28 28  '1C
% ContinuousController29 29  '1D
% ContinuousController30 30  '1E
% ContinuousController31 31  '1E


'http://www.midi.org/techspecs/midimessages.php

% NoteOff                0x80
% NoteOn                0x90
% PolyphonicKeyPressure 0xA0
% ControlChange         0xB0
% ProgramChange         0xC0
% ChannelPressure       0xD0
% PitchWheelChange      0xE0
% SystemCommand         0xF0


% SystemExclusive       0xF0
% MidiTimeCode          0xF1 'quarter frame
% SongPositionPointer   0xF2 'number of midi beats (6 beatS per clock) since start of song
% SongSelect            0xF3
% Undefined             0xF4
% Undefined             0xF5
% TuneRequest           0xF6
% EndofExclusive        0xF7

% TimingClock           0xF8 '24 times /qtr note
% Undefined             0xF9
% StartSequence         0xFA
% ContinueSequence      0xFB
% StopSequence          0xFC
% Undefined             0xFD
% ActiveSensing         0xFE
% Reset                 0xFF


'Tuning program change
'
'Bn 64 00 65 03 06 tt (data entry)
'Bn 64 00 65 03 60 7F (data increment)
'Bn 64 00 65 03 61 7F (data decrement)
'                     
'n = basic channel number
'tt = tuning program number from 1 to 128
'
'Frequency data format (all bytes in hex)
'
'xx = semitone (MIDI note number to retune to, unit is 100 cents)
'yy = MSB of fractional part (1/128 semitone = 100/128 cents = .78125 cent units)
'zz = LSB of fractional part (1/16384 semitone = 100/16384 cents = .0061 cent units)
'
'7F 7F 7F is reserved for no change to the existing note tuning





'octave 0..10
extern lib "Winmm.dll"

% MAXPNAMELEN 32

% __in
% __out
% __in_opt
% __inout

% CALLBACK_TYPEMASK   0x00070000l     'callback type mask
% CALLBACK_NULL       0x00000000l     'no callback
% CALLBACK_WINDOW     0x00010000l     'dwCallback is a HWND
% CALLBACK_TASK       0x00020000l     'dwCallback is a HTASK
% CALLBACK_FUNCTION   0x00030000l     'dwCallback is a FARPROC
% CALLBACK_THREAD     (CALLBACK_TASK) 'thread ID replaces 16 bit task
% CALLBACK_EVENT      0x00050000l     'dwCallback is an EVENT Handle

type MIDIOUTCAPSA
    word    wMid;                  'manufacturer ID
    word    wPid;                  'product ID
    dword   vDriverVersion;        'version of the driver
    char    szPname[MAXPNAMELEN];  'product name (NULL terminated string)
    word    wTechnology;           'type of device
    word    wVoices;               '# of voices (internal synth only)
    word    wNotes;                'max # of notes (internal synth only)
    word    wChannelMask;          'channels used (internal synth only)
    dword   dwSupport;             'functionality supported by driver
end type


/* flags for wTechnology field of MIDIOUTCAPS structure */
% MOD_MIDIPORT    1  'output port
% MOD_SYNTH       2  'generic internal synth
% MOD_SQSYNTH     3  'square wave internal synth
% MOD_FMSYNTH     4  'FM internal synth
% MOD_MAPPER      5  'MIDI mapper
% MOD_WAVETABLE   6  'hardware wavetable synth
% MOD_SWSYNTH     7  'software synth

/* flags for dwSupport field of MIDIOUTCAPS structure
% MIDICAPS_VOLUME          0x0001  'supports volume control
% MIDICAPS_LRVOLUME        0x0002  'separate left-right volume control
% MIDICAPS_CACHE           0x0004
% MIDICAPS_STREAM          0x0008  'driver supports midiStreamOut directly

/* MIDI data block header */

typedef dword* dword_ptr

type midihdr
    sys         lpData;              'pointer to locked data block
    dword       dwBufferLength;      'length of data in data block
    dword       dwBytesRecorded;     'used for input only
    sys         dwUser;              'for client's use
    dword       dwFlags;             'assorted flags (see defines)
    sys lpnext
    'struct midihdr *  lpNext;       'reserved for driver
    dword*      reserved;            'reserved for driver
    dword       dwOffset;            'Callback offset into buffer
    dword_ptr   dwReserved[8];       'Reserved for MMSYSTEM
end type


type midievent
    dword       dwDeltaTime;          'Ticks since last event
    dword       dwStreamID;           'Reserved; must be zero
    dword       dwEvent;              'Event type and parameters
    dword       dwParms[1];           'Parameters if this is a long event
end type

type midistrmbuffver
    dword       dwVersion;            'Stream buffer format version
    dword       dwMid;                'Manufacturer ID as defined in MMREG.H
    dword       dwOEMVersion;         'Manufacturer version for custom ext
end type

/* flags for dwFlags field of MIDIHDR structure */
% MHDR_DONE       0x00000001       'done bit
% MHDR_PREPARED   0x00000002       'set if header prepared
% MHDR_INQUEUE    0x00000004       'reserved for driver
% MHDR_ISSTRM     0x00000008       'Buffer is stream buffer


sys midiOutGetNumDevs(void)

sys midiConnect(sys hmi,hmo,pReserved)
sys midiDisconnect(sys hmi, hmo,pReserved)

sys midiOutGetDevCapsA(sys uDeviceID, MIDIOUTCAPSA *pmoc,sys cbmoc)
sys midiOutGetVolume(sys hmo, *pdwVolume)
sys midiOutSetVolume(sys hmo,dwVolume)
sys midiOutGetErrorTextA(sys mmrError,string pszText, sys cchText)
sys midiOutOpen(sys *phmo, uDeviceID,dwCallback, dwInstance,fdwOpen)
sys midiOutClose( sys hmo);
sys midiOutShortMsg( sys hmo, dwMsg)
sys midiOutReset(sys hmo)
sys midiOutGetID(sys hmo, *puDeviceID)
sys midiOutMessage(sys hmo,uMsg,dw1,dw2)

sys midiOutPrepareHeader(sys  hmo, lpMidiOutHdr, cbMidiOutHdr)
sys midiOutUnprepareHeader(sys hmo, lpMidiOutHdr, cbMidiOutHdr )
sys midiOutLongMsg(sys  hmo, lpMidiOutHdr, cbMidiOutHdr)

end extern

