Mirage Engine
Simple DirectX MIDI's - Printable Version

+- Mirage Engine (https://mirage-engine.uk/forums)
+-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61)
+--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18)
+---- Forum: Resources (https://mirage-engine.uk/forums/forumdisplay.php?fid=49)
+---- Thread: Simple DirectX MIDI's (/showthread.php?tid=1942)



Simple DirectX MIDI's - jsventor - 20-07-2008

Ok its all client, and its simple, just change ModSound to this,
Code:
Public Sub StopMIDI()
On Error Resume Next
    Preformance.Stop Segment, Nothing, 0, 0
End Sub

Public Sub PlaySound(Sound As String)
    Call sndPlaySound(App.Path & "\" & Sound, SND_ASYNC Or SND_NOSTOP)
End Sub

Public Sub PlayMidi(filename As String)
On Error Resume Next
    Set Segment = Loader.LoadSegment(filename)
    If Err.Number  DD_OK Then MsgBox "Error: Could not load MIDI file!", vbExclamation, "ERROR!"
    Preformance.PlaySegment Segment, 0, 0
End Sub

And then search for ' Play Music and change it to,
Code:
' Play music
        Call StopMIDI
        If Map.Music > 0 Then
        Call PlayMIDI(App.Path & "\Music\" & "music" & Trim(STR(Map.Music)) & ".mid")
        End If
        
        Exit Sub
    End If

Add this in sub InitDirectX
Code:
Call InitializeMusic

Add this to the bottom of ModDirectX
Code:
Sub InitializeMusic()

Set Loader = DX.DirectMusicLoaderCreate
    Set Preformance = DX.DirectMusicPerformanceCreate
        Preformance.Init Nothing, frmMirage.hWnd
        Preformance.SetPort -1, 1
        Preformance.SetMasterAutoDownload True
    If Err.Number  DD_OK Then

    End If
    
End Sub

And last but not least add this in with your declares,
Code:
' for playing music
Public Loader As DirectMusicLoader
Public Preformance As DirectMusicPerformance
Public Segment As DirectMusicSegment

And if you have a preview button in the map editor add this to your buttons,

PREVIEW
Code:
PlayMIDI(App.Path & "\Music\" & "music" & scrlMusic.Value & ".mid")

STOP
Code:
StopMIDI



Re: Simple DirectX MIDI's - Robin - 20-07-2008

Isn't there already a tutorial for this?

Could have sworn I wrote it up >_>


Re: Simple DirectX MIDI's - jsventor - 20-07-2008

Oh I had no clue, dont see it though >.


Re: Simple DirectX MIDI's - Poyzin - 20-07-2008

Jsventor where have you been on MSN?? Been waiting for u fer like 3 weeks!!!

Also, nice tut. I'm gonna use that one Big Grin


Re: Simple DirectX MIDI's - jsventor - 21-07-2008

Poyzin Wrote:Jsventor where have you been on MSN?? Been waiting for u fer like 3 weeks!!!

Also, nice tut. I'm gonna use that one Big Grin

I was in the big apple Big Grin


Re: Simple DirectX MIDI's - Mozza - 22-07-2008

http://www.mikeschmoyer.com/tutorials/vb_dxmusic.htm


Re: Simple DirectX MIDI's - Robin - 22-07-2008

Mark, that tutorial doesn't handle how to do it in Mirage itself so it's made obsolete by Jsventor.

Jsventor, it's pretty nice but I don't understand why you have to load the midi then play it.

I quickly merged those two together:

Code:
Public Sub PlayMidi(filename As String)
On Error Resume Next
    Set Segment = Loader.LoadSegment(filename)
    If Err.Number  DD_OK Then MsgBox "Error: Could not load MIDI file!", vbExclamation, "ERROR!"
    Preformance.PlaySegment Segment, 0, 0
End Sub

Delete LoadMIDI and replace PlayMidi with the above.


Re: Simple DirectX MIDI's - jsventor - 23-07-2008

Robin Wrote:Mark, that tutorial doesn't handle how to do it in Mirage itself so it's made obsolete by Jsventor.

Jsventor, it's pretty nice but I don't understand why you have to load the midi then play it.

I quickly merged those two together:

Code:
Public Sub PlayMidi(filename As String)
On Error Resume Next
    Set Segment = Loader.LoadSegment(filename)
    If Err.Number  DD_OK Then MsgBox "Error: Could not load MIDI file!", vbExclamation, "ERROR!"
    Preformance.PlaySegment Segment, 0, 0
End Sub

Delete LoadMIDI and replace PlayMidi with the above.

I honestly didn't even think of that.. wow, thanks, I'm trying to learn DX right now, so, although I might post things that work I'm not sure if its the best methods I'm using, so the help is always appreciated Tongue