Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple DirectX MIDI's
#1
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
Reply
#2
Isn't there already a tutorial for this?

Could have sworn I wrote it up >_>
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#3
Oh I had no clue, dont see it though >.
Reply
#4
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
Reply
#5
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
Reply
#6
http://www.mikeschmoyer.com/tutorials/vb_dxmusic.htm
Reply
#7
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.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#8
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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)