MIDI gamut

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by merendo.

Hi @ll

I want to play a simple gamut (C1 to C2) using the API-MIDI commands. Can anyone help me to do this? Thank you!

Cu @ll, merendo
--
Damn it. I don't know what to write here. Well, simply: Thanks to everybody, who helps me. I hope we are not going to have any problems.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

HI merendo..
search on the forum... someone posted a nice example long time ago...
You can take a look to pauls resource site where you should find the
example as zip too.

PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by merendo.

Hmm... I'm sorry but I didn't find anything...

Cu @ll, merendo
--
Damn it. I don't know what to write here. Well, simply: Thanks to everybody, who helps me. I hope we are not going to have any problems.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Kale.

http://www.reelmediaproductions.com/pb/ ... i_midi.zip :)

--Kale

New to PureBasic and falling in Love! :)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by merendo.

@Kale: Sure. I also found this example, but I want to play a gamut. (German: Tonleiter) From c1 to c2, c d e f g a b c. Is there any example, which shows how to do this via API_MIDI?

Cu @ll, merendo
--
Damn it. I don't know what to write here. Well, simply: Thanks to everybody, who helps me. I hope we are not going to have any problems.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by merendo.

Anybody can help me?

Cu @ll, merendo
--
Damn it. I don't know what to write here. Well, simply: Thanks to everybody, who helps me. I hope we are not going to have any problems.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

Code: Select all

;
; by Danilo, 25.12.2002
;
Global hMidiOut
#Church_organ    = 19
#Orchestral_harp = 46
#Channel1 = 1
#Channel2 = 2

Procedure MidiOutMessage(hMidi,iStatus,iChannel,iData1,iData2)
     dwMessage = iStatus | iChannel | (iData1 << 8) | (iData2 << 16)
     ProcedureReturn midiOutShortMsg_(hMidi, dwMessage) ;
EndProcedure

Procedure SetInstrument(channel,instrument)
   MidiOutMessage(hMidiOut, $C0,  channel, instrument, 0)
EndProcedure

Procedure PlayNote(channel,Note)
   MidiOutMessage(hMidiOut, $90, channel, Note , 127)
EndProcedure

Procedure StopNote(channel,Note)
   MidiOutMessage(hMidiOut, $90, channel, Note , 0)
EndProcedure

; open MIDI out
If midiOutOpen_(@hMidiOut,0, 0, 0, 0) = #MMSYSERR_NOERROR
   
   ; set harp as instrument
   SetInstrument(#Channel1,#Orchestral_harp)
   SetInstrument(#Channel2,#Orchestral_harp)
   
   ; play notes from c2 to c4
   For a = $2C To $4C Step 2
       PlayNote(#Channel1,a) : PlayNote(#Channel2,a)
       Delay(125)
       StopNote(#Channel1,a) : StopNote(#Channel2,a)
   Next a

   ; play notes from c4 to c1 (backwards)
   For a = $4C To $1C Step -2
       PlayNote(#Channel1,a) : PlayNote(#Channel2,a)
       Delay(125)
       StopNote(#Channel1,a) : StopNote(#Channel2,a)
   Next a
   
   ; small pause
   Delay(300)
   
   ; set church organ as instrument
   SetInstrument(#Channel1, #Church_organ)
   SetInstrument(#Channel2, #Church_organ)
   
   ; play J.S.Bach notes
   Restore Bach_Toccata_in_D_Minor
   For a = 1 To 60
       Read note
       PlayNote(#Channel1,note) : PlayNote(#Channel2,note)
       Delay(110)
       StopNote(#Channel1,note) : StopNote(#Channel2,note)
   Next a

   ; end: reset instruments to 0 (default)
   SetInstrument(#Channel1,0)
   SetInstrument(#Channel2,0)
   ; end: close MIDI output
   midiOutClose_(hMidiOut)
EndIf
End

DataSection
  Bach_Toccata_in_D_Minor:
    Data.l 110, 69, 81,  110, 67, 79,  990, 69, 81,  220, -1, -1
    Data.l 110, 67, 79,  110, 65, 77,  110, 64, 76,  110, 62, 74
    Data.l 220, 61, 73,  440, 62, 74, 1980, -1, -1,  110, 57, 69
    Data.l 110, 55, 67,  990, 57, 69,  220, -1, -1,  220, 52, 64
    Data.l 220, 53, 65,  220, 49, 61,  440, 50, 62, 1980, -1, -1
EndDataSection
Note 'c1' is $1C and note 'c2' is $2C and so on...
...hope it helps.

cya,
...Danilo
(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

hi merendo,
here is a small example of playing any melody you want (without speed and pause controls). This example will play something like C,D,E... (you have to check the vals if the val 48 mean C2 or not... I dont know atm... But take a look to MIDI or API docs...

Code: Select all

Structure MIDIDATA
  Channel.b
  Note.b
  Velocity.b
  Null.b
EndStructure
;
midi.MIDIOUTCAPS
devices=midiOutGetNumDevs_()
For devnum=-1 To devices-1
  If midiOutGetDevCaps_(devnum,@midi,SizeOf(MIDIOUTCAPS))=0
    If midi\wVoices>0
      midiport=devnum
    EndIf
  EndIf
Next 
;
*hMidiOut.l
result=midiOutOpen_(@hMidiOut,midiport,0,0,0)
;
Note.b=48                           ; Define Midi Note
Vel.b=127
Channel.b=1
Instrument.b=12                     ; Midi Instrument
;
dMsg.MIDIDATA\Note=Instrument
dMsg\Channel=$bf+Channel
result=midiOutShortMsg_(hMidiOut,PeekW(dMsg))
;
For x = 1 To 8                      ; Play 8 Notes, take a look to DataSection
  dMsg\Velocity=Vel
  Read Note                         ; Read next Note from DataSection
  dMsg\Note=Note 
  dMsg\Channel=$8f+Channel
  result=midiOutShortMsg_(hMidiOut,PeekL(dMsg))
  Delay(50)
  dMsg\Velocity=Vel
  dMsg\Note=Note
  dMsg\Channel=$7f+Channel
  result=midiOutShortMsg_(hMidiOut,PeekL(dMsg))
  Delay(130)                        ; Small pause between every note
Next 
;
result=midiOutClose_(hMidiOut)
End
;
; -------- Play Notes / Melody --------
;
DataSection
  Data.b 48,49,50,51,52,53,54,55    ; 8 Notes stored (check if 48 = C2 !?)
EndDataSection
Melody of "AlleMeineEnten" could look something like:
Data.b 48,49,50,51,52,52
Data.b 53,53,53,53, 52




PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

Uiii, Danilo was faster when i was on WC :wink:


PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

Hi Danilo,
i tested your example with the nice bach melody, i was to tired to add a "oh susanna" melody or whatever in my example... Your source does not plays any melody on my system, so i changed your code a bit to get it work on my system too... here is your fixed version...

Code: Select all

Procedure SetInstrument(channel,instrument)
   MidiOutMessage(hMidiOut, $C0,  channel, instrument, 0)
EndProcedure

Procedure PlayNote(channel,Note)
   MidiOutMessage(hMidiOut, $90, channel, Note , 127)
EndProcedure

Procedure StopNote(channel,Note)
   MidiOutMessage(hMidiOut, $90, channel, Note , 0)
EndProcedure

midi.MIDIOUTCAPS

devices = MidiOutGetNumDevs_()
For devnum=-1 To devices-1
  If midiOutGetDevCaps_(devnum,@midi,SizeOf(MIDIOUTCAPS))=0
    If midi\wVoices>0
      midiport=devnum
    EndIf
  EndIf
Next 
;
*hMidiOut.l
;
If midiOutOpen_(@hMidiOut,midiport,0,0,0) = #MMSYSERR_NOERROR
   ; set harp as instrument
   SetInstrument(#Channel1,#Orchestral_harp)
   SetInstrument(#Channel2,#Orchestral_harp)
   
   ; play notes from c2 to c4
   For a = $2C To $4C Step 2
       PlayNote(#Channel1,a) : PlayNote(#Channel2,a)
       Delay(125)
       StopNote(#Channel1,a) : StopNote(#Channel2,a)
   Next a

   ; play notes from c4 to c1 (backwards)
   For a = $4C To $1C Step -2
       PlayNote(#Channel1,a) : PlayNote(#Channel2,a)
       Delay(125)
       StopNote(#Channel1,a) : StopNote(#Channel2,a)
   Next a
   
   ; small pause
   Delay(300)
   
   ; set church organ as instrument
   SetInstrument(#Channel1, #Church_organ)
   SetInstrument(#Channel2, #Church_organ)
   
   ; play J.S.Bach notes
   Restore Bach_Toccata_in_D_Minor
   For a = 1 To 60
       Read note
       PlayNote(#Channel1,note) : PlayNote(#Channel2,note)
       Delay(110)
       StopNote(#Channel1,note) : StopNote(#Channel2,note)
   Next a

   ; end: reset instruments to 0 (default)
   SetInstrument(#Channel1,0)
   SetInstrument(#Channel2,0)
   ; end: close MIDI output
   midiOutClose_(hMidiOut)
EndIf
End

DataSection
  Bach_Toccata_in_D_Minor:
    Data.l 110, 69, 81,  110, 67, 79,  990, 69, 81,  220, -1, -1
    Data.l 110, 67, 79,  110, 65, 77,  110, 64, 76,  110, 62, 74
    Data.l 220, 61, 73,  440, 62, 74, 1980, -1, -1,  110, 57, 69
    Data.l 110, 55, 67,  990, 57, 69,  220, -1, -1,  220, 52, 64
    Data.l 220, 53, 65,  220, 49, 61,  440, 50, 62, 1980, -1, -1
EndDataSection
PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by NicTheQuick.

Who can tell me more about the different iStatus arguments in this procedure?

Procedure MidiOutMessage(hMidi,iStatus,iChannel,iData1,iData2)
dwMessage = iStatus | iChannel | (iData1 << 8) | (iData2 << 16)
ProcedureReturn midiOutShortMsg_(hMidi, dwMessage) ;
EndProcedure

I want change the bank of my synthesizer, pitch a note or set a controller like "Panorama", "Modulation", "Expression", "Volume", "Chorus", "Soft Pedal", "Hall", etc.
There are 127 controllers with 127 possibilities and a lot of banks on different synthesizer!

And I want receive all notes and controller settings from my keyboard as midi-in device.

Can anyone help me to do this?

Thanks a lot!!
Post Reply