Solved

Sending MIDI notes - polyphonic (Chords)

Posted on 2014-11-19
4
291 Views
Last Modified: 2014-11-19
This is a follow up to my earlier question (closed) here
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_28562826.html

I got it to play single notes, thanks to Qlemo.
The notes play one-after-the-other. ie. monophonically. I'd like to play several notes at the same time (polyphonic). So I did this to test (lines 10 and 11)

Sub PlayMIDI(voiceNum, noteNum, Duration)
    Dim Note As Long
    Dim i As Integer
    
    On Error Resume Next
    midiOutShortMsg hMidiOut, RGB(192, voiceNum - 1, 127)
    lanote = 0 + CLng(noteNum)

    midiOutShortMsg hMidiOut, RGB(144, lanote, 127)
    midiOutShortMsg hMidiOut, RGB(144, lanote + 3, 127)
    midiOutShortMsg hMidiOut, RGB(144, lanote + 5, 127)
    
    Sleep (Duration)
    midiOutShortMsg hMidiOut, RGB(128, lanote, 127)
    
 End Sub

Open in new window


And yes, it plays a chord. But if I fire off individual notes by calling that sub on each note the next note doesn't start until the previous one has ended.

It's the same if I comment out the Note Off event
    midiOutShortMsg hMidiOut, RGB(128, lanote, 127)

So what I'm after is, to be able to fire off a Note via a Sub as above but for the Notes playing to continue until the Note Off event.

Does anyone know how please?
0
Comment
Question by:hindersaliva
  • 2
  • 2
4 Comments
 
LVL 69

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40453697
I'm sorry to tell you that, but you can't do that with Excel, at least with reasonable effort.
Sequencers and Synths are doing that by putting each note with duration into a queue when played, and decrement the duration by one quantum on each run thru the player loop. If duration hits zero, a Note Off is sent.

This sub however plays something, and waits until the duration has passed (sleep). Then sends a Note Off. Then returns to the caller, allowing to play another note.

Also remember that the duration in the Excel example is the note length, not the duration of the sound. The sound of a snare drum hit is very short, no matter how long you "play" that note, to use an extreme example.
0
 

Author Comment

by:hindersaliva
ID: 40453978
Hey, I got it to work.

I have a counter that counts each tick. That's measure > beat > tick. See?

Sub PlayMIDIList()

    Dim iMeasure As Integer
    Dim iBeat As Integer
    Dim iTick As Integer
    Dim strSongPosition As String
    Dim iRow As Integer
    Dim intMsg As Integer
    Dim intNote As Integer
    Dim intVelocity As Integer
    
    On Error Resume Next
    
    midiOutOpen hMidiOut, 0, 0, 0, 0

    For iMeasure = 1 To 16
        For iBeat = 1 To 4
            For iTick = 1 To 384
                strSongPosition = Trim(Str(iMeasure)) + "." + Trim(Str(iBeat)) + "." + Trim(Str(iTick))

                For iRow = 6 To 50
                    If Cells(iRow, 2).Value = strSongPosition Then
                        intMsg = Cells(iRow, 3).Value       'Note on/Note off
                        intNote = Cells(iRow, 5).Value      'Note no
                        intVelocity = 127                   'Key velocity (=volume)
                        midiOutShortMsg hMidiOut, RGB(intMsg, intNote, intVelocity)

                    End If
                Next iRow

            Next iTick
        Next iBeat
    Next iMeasure
    
    midiOutClose hMidiOut
   
 End Sub

Open in new window


My MIDI data looks like this

SongPosition      Msg      Voice      Note
1.1.1              144      1              60
3.2.1              144      1              64
8.4.38              128      1              64
8.1.384              128      1              60
10.1.1              144      1              70
10.1.1              144      1              74
10.1.1              144      1              77
14.1.380              128      1              70
14.1.380              128      1              74
14.1.380              128      1              77
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 40453984
As I said :D
0
 

Author Comment

by:hindersaliva
ID: 40453987
Yes. Thanks Qlemo.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now