Solved

mciSendString notification

Posted on 1997-09-10
5
413 Views
Last Modified: 2012-08-14
VB5
Trying to loop or continuously play MIDI files.  I am using the API call rather than the MCI control.
The API parameters can include 'notify' , so how can I trap the notifiy event to determine when the MIDI file has completed?
Is there a better (another) way to loop MIDI files?
Thanks for your help.
Barry
0
Comment
Question by:BWATERS
  • 3
5 Comments
 

Author Comment

by:BWATERS
ID: 1434524
Edited text of question
0
 
LVL 1

Expert Comment

by:eyvind081997
ID: 1434525
Why not use the MCI control? In the done event you can play it all over again.
0
 

Author Comment

by:BWATERS
ID: 1434526
Thanks for the quick response.
I'd rather not use the MCI control as all I am doing is playing MIDI files and do not want to add 'overhead'.  Also, strictly from a programming point of view (and a desire to learn), I find it frustrating that WAV files can be looped easily enough...why not MIDI files.
0
 

Accepted Solution

by:
Wyatt090997 earned 200 total points
ID: 1434527
Bwaters:

Below is a sample source which will loop a midi file continuously until you call it to stop. You can set the length of the midi exactly, or where inside the midi you'd like it to stop and then loop. You can also post your email address and I will send you this sample application as a zip file. This prog only needs VB Runtime (I used 4 32 bit, but you could bring it into 5 easily) and the winmm.dll as it uses the "mciSendString."

Create a new program and place 2 command buttons and a timer on form1. You will also need a Module1:

'in general declarations of Form1 place the following sub:

Sub PlayBackGround()
    'Start Background Midi
    'Play the MIDI "TEST.MID" file aliased as "MyMidi".
    result = mciSendString("open " & App.Path & "\TEST.MID type sequencer alias MyMidi", 0&, 0, 0)
   
    'Error correction. REM out when debugging
    On Error Resume Next

    'Dim result As Long
    Dim X!

    'This is where we bring it back to each time.
StartAgain:
    result = mciSendString("close all", 0&, 0, 0)
    'Reload the MIDI file.
    result = mciSendString("open " & App.Path & "\TEST.MID type sequencer alias MyMidi", 0&, 0, 0)

    'Timer settings. I guess 1000 is the default.
    Form1.Timer1.Interval = 1000
    Form1.Timer1.Enabled = True
    X! = Timer
    Do
        result = mciSendString("play MyMidi", 0&, 0, 0)
        DoEvents
   
        'Just set the length of the midi file below
        'and loop until the set time is over (length of midi).
           
    Loop While Abs(Timer - X!) <= 10 'Midi Length in seconds

        'close the midi player to avoid hanging it :-)
        result = mciSendString("close all", 0&, 0, 0)

        'Send it back to the top
        GoTo StartAgain
End Sub

'command button1:
Private Sub Play_Click()
PlayBackGround
End Sub

'command button2:
Private Sub Stop_Click()
Dim result As Long
    'Close background music
    result = mciSendString("close all", 0&, 0, 0)
End
End Sub

'place in MODULE1:

Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

Public result

--------------------

Just replace TEST.MID with the name of your MIDI file OR rename your MIDI file TEST.MID. Set your midi length (10 'Midi Length in seconds) this example is 10 seconds...but you can set it to the exact length of yours (or to what point you want to loop).

Wyatt
0
 

Author Comment

by:BWATERS
ID: 1434528
Wyatt, thanks for the reponse.
Rather unique...not what I had asked, but acceptable as a solution; higher marks if you had also included a procedure/function that would  determine the length (in seconds) of different MIDI files.  Your solution assumes the programmer knows the length of the MIDI file being played.n Still a chance to go to the head of the class.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

758 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

21 Experts available now in Live!

Get 1:1 Help Now