Low level MIDI on a PC

ok, I'm trying to write a program that can send out midi data, and maybe later take it in as well.



thru pure trial and error I found that writing to port [Midiport]+3 sends out midi data. I also know the midi codes I want to be sending; the only problem is it would seem the correct data is not being sent.



does the sound card handle sending the midi data out at the correct rate or should my program?



I edited my program so it would and it still didnt work.



I'm just trying to get the device the midi data is being sent to to play a note.



also, when I send loads of random data to the port, the device does play random notes.



does anyone have any idea about the correct way to use MIDI hardware in a pc?


Comments

  • Hello My friend



    The only thing i can do for is that I know how to send MIDI data to outport using VB I am giving code for that its very easy





    Private Const MIDI_MAPPER = -1

    Dim hmidi as Long,midimsg as long



    Private Declare Function midiOutClose Lib "winmm.dll" (ByVal hMidiOut As Long) As Long

    Private Declare Function midiOutOpen Lib "winmm.dll" (lphMidiOut As Long, ByVal uDeviceID As Long, ByVal dwCallback As Long, ByVal dwInstance As Long, ByVal dwFlags As Long) As Long

    Private Declare Function midiOutShortMsg Lib "winmm.dll" (ByVal hMidiOut As Long, ByVal dwMsg As Long) As Long







    ''How To call



    rc = midiOutClose(hmidi) 'Close previouse MIDI

    rc = midiOutOpen(hmidi, MIDI_MAPPER, 0, 0, 0) 'Open again





    SendNoteToMIDI 40,2,70 'Send Note number,channel Number,vol

    for dl=1 to 10000 step .1:next dl 'Delay

    StopNote 40,2 'Stop note at channel U can play 4 note at the same time at one channel and there r 16 channel



    SetChanToSOUND 2,10 'U can set a particular sound to a channel like flute,guitar,,rang 0-127





    Private Sub SendNoteToMIDI(Note As Integer, Channel As Integer, volume As Integer)

    midimsg = &H90 + (Note * &H100) + (volume * &H10000) + Channel

    midiOutShortMsg hmidi, midimsg

    End Sub



    Private Sub StopNote(Note As Integer, Channel As Integer)

    midimsg = &H80 + (Note * &H100) + Channel

    midiOutShortMsg hmidi, midimsg

    End Sub





    Private Sub SetChanToSOUND(chan As Integer, soud As Integer)

    Dim mess As Long, low As Long, hig As Long

    Dim mev, mn, mvel As Long



    mev = &HC0 + 2

    mn = Val(Text4)

    mvel = 0

    low = (mn * 256) + mev

    hig = (mvel * 256) * 256



    mess = low + hig

    RetValue% = midiOutShortMsg(hMidi, mess)

    End Sub











    : ok, I'm trying to write a program that can send out midi data, and maybe later take it in as well.

    :

    : thru pure trial and error I found that writing to port [Midiport]+3 sends out midi data. I also know the midi codes I want to be sending; the only problem is it would seem the correct data is not being sent.

    :

    : does the sound card handle sending the midi data out at the correct rate or should my program?

    :

    : I edited my program so it would and it still didnt work.

    :

    : I'm just trying to get the device the midi data is being sent to to play a note.

    :

    : also, when I send loads of random data to the port, the device does play random notes.

    :

    : does anyone have any idea about the correct way to use MIDI hardware in a pc?

    :






  • When i use your code i get no sound wot so ever, am i doing something wrong or have u missed something?





    : Private Const MIDI_MAPPER = -1

    : Dim hmidi as Long,midimsg as long

    :

    : Private Declare Function midiOutClose Lib "winmm.dll" (ByVal hMidiOut As Long) As Long

    : Private Declare Function midiOutOpen Lib "winmm.dll" (lphMidiOut As Long, ByVal uDeviceID As Long, ByVal dwCallback As Long, ByVal dwInstance As Long, ByVal dwFlags As Long) As Long

    : Private Declare Function midiOutShortMsg Lib "winmm.dll" (ByVal hMidiOut As Long, ByVal dwMsg As Long) As Long

    :

    :

    :

    : ''How To call

    :

    : rc = midiOutClose(hmidi) 'Close previouse MIDI

    : rc = midiOutOpen(hmidi, MIDI_MAPPER, 0, 0, 0) 'Open again

    :

    :

    : SendNoteToMIDI 40,2,70 'Send Note number,channel Number,vol

    : for dl=1 to 10000 step .1:next dl 'Delay

    : StopNote 40,2 'Stop note at channel U can play 4 note at the same time at one channel and there r 16 channel

    :

    : SetChanToSOUND 2,10 'U can set a particular sound to a channel like flute,guitar,,rang 0-127

    :

    :

    : Private Sub SendNoteToMIDI(Note As Integer, Channel As Integer, volume As Integer)

    : midimsg = &H90 + (Note * &H100) + (volume * &H10000) + Channel

    : midiOutShortMsg hmidi, midimsg

    : End Sub

    :

    : Private Sub StopNote(Note As Integer, Channel As Integer)

    : midimsg = &H80 + (Note * &H100) + Channel

    : midiOutShortMsg hmidi, midimsg

    : End Sub

    :

    :

    : Private Sub SetChanToSOUND(chan As Integer, soud As Integer)

    : Dim mess As Long, low As Long, hig As Long

    : Dim mev, mn, mvel As Long

    :

    : mev = &HC0 + 2

    : mn = Val(Text4)

    : mvel = 0

    : low = (mn * 256) + mev

    : hig = (mvel * 256) * 256

    :

    : mess = low + hig

    : RetValue% = midiOutShortMsg(hMidi, mess)

    : End Sub

    :




  • To initialize, put 3F into port 1. Then read one byte from port 0. Then wait until bit 7 of port 1 becomes cleared.

    To send a byte, write it to port 0. Then read one byte from port 0 and wait until bit 6 of port 1 becomes cleared. By port 0 and 1 I mean the midi port and the one immediately following it.

    If you write data when the MPU isn't ready, it could miss some bytes.


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories