Solved

mciSendString notification

Posted on 1997-09-10
5
427 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

777 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