How to use a MIDI with DirectX?

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 3075 Views - Last Post: 26 May 2011 - 08:32 PM Rate Topic: -----

#1 Heart's Soul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 12-April 11

How to use a MIDI with DirectX?

Posted 12 April 2011 - 04:08 PM

I'm using VB .NET for programming at my high school, and I've went and started to do my own project for amusement at home.

So, I'm using a Console Application for a text-based video game, and I've thought about adding MIDI audio to my project. I've already composed a prototype song through FL Studio and added it to my resources, but I'm stuck-

The actual question: How do I use DirectX (which was never mentioned at all in my school) to make a MIDI able to play and loop indefinitely?

I've searched through Google for three days, having errors of many types (including one where it couldn't even find a type), but I'm entirely stuck. I don't want to go to WAV files, since they are huge, especially for 13-second loops, but I need to get music working. And, yes, I've Imported DirectX to my app.

I've only Dimmed a variable as Audio, but didn't get much farther than that. Does anybody who knows some DirectX help a kid?

Is This A Good Question/Topic? 0
  • +

Replies To: How to use a MIDI with DirectX?

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: How to use a MIDI with DirectX?

Posted 12 April 2011 - 04:26 PM

Have you checked out DirectSound? It's a component of directX that will allow you to do what you want to do. :)
Was This Post Helpful? 0
  • +
  • -

#3 Heart's Soul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 12-April 11

Re: How to use a MIDI with DirectX?

Posted 12 April 2011 - 05:44 PM

View PostButchDean, on 12 April 2011 - 04:26 PM, said:

Have you checked out DirectSound? It's a component of directX that will allow you to do what you want to do. :)

Yes, however, that only explains how WAVs play, and I could easily do what I require without DirectX if I didn't choose MIDI.
Was This Post Helpful? 0
  • +
  • -

#4 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1009
  • View blog
  • Posts: 4,209
  • Joined: 14-February 08

Re: How to use a MIDI with DirectX?

Posted 13 April 2011 - 03:34 AM

You should look into winmm it's an API to use multimedia that comes with windows to play and manipulate MIDI and other things.
Was This Post Helpful? 0
  • +
  • -

#5 Heart's Soul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 12-April 11

Re: How to use a MIDI with DirectX?

Posted 13 April 2011 - 07:20 AM

View Poststayscrisp, on 13 April 2011 - 03:34 AM, said:

You should look into winmm it's an API to use multimedia that comes with windows to play and manipulate MIDI and other things.

Would be helpful, except that it's not for .NET and that I have no intentions of writing a lot of code just to get it to work, since I need to make the game as light as possible (able to run on Windows 98).
Was This Post Helpful? 0
  • +
  • -

#6 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1009
  • View blog
  • Posts: 4,209
  • Joined: 14-February 08

Re: How to use a MIDI with DirectX?

Posted 13 April 2011 - 08:01 AM

Well look into this http://winmm.codeplex.com/
Was This Post Helpful? 0
  • +
  • -

#7 Heart's Soul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 12-April 11

Re: How to use a MIDI with DirectX?

Posted 13 April 2011 - 10:45 AM

View Poststayscrisp, on 13 April 2011 - 08:01 AM, said:

Well look into this http://winmm.codeplex.com/

Thanks, I'm googling to see how to get it to play a MIDI.

I still would like to know how to get DirectX working with a resource, through the Audio type.
Was This Post Helpful? 0
  • +
  • -

#8 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1009
  • View blog
  • Posts: 4,209
  • Joined: 14-February 08

Re: How to use a MIDI with DirectX?

Posted 13 April 2011 - 11:22 AM

How about this? http://www.vb-helper...rectx_midi.html
Was This Post Helpful? 0
  • +
  • -

#9 Heart's Soul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 12-April 11

Re: How to use a MIDI with DirectX?

Posted 13 April 2011 - 02:10 PM

View Poststayscrisp, on 13 April 2011 - 11:22 AM, said:


Well, I already checked that link- it doesn't explain how to use resources, and it's more than just placing My.Resources.P64_3 instead of the text in the brackets.
Was This Post Helpful? 0
  • +
  • -

#10 Heart's Soul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 12-April 11

Re: How to use a MIDI with DirectX?

Posted 19 April 2011 - 05:20 PM

Okay, I had a huge error, and it was obvious.

I had to move the mid file. *sigh*

Anyway, now the problem is getting it to loop. Event handlers did nothing for me, since I'm running a ConsoleApplication. Anyone have the code on how to get it right, help a newb?
Was This Post Helpful? 0
  • +
  • -

#11 Heart's Soul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 12-April 11

Re: How to use a MIDI with DirectX?

Posted 22 April 2011 - 09:50 AM

As it turns out, you can't edit posts.

Anyway, I've been following this tutorial down to the word, but the only problem is that the AddHandler code isn't even executed. I added a someAudio.Ending handler, like in the tutorial, but the audio never loops. In fact, the handler isn't even activated!

Anybody know how I can audio to loop using DirectX flawlessly?
Was This Post Helpful? 0
  • +
  • -

#12 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1009
  • View blog
  • Posts: 4,209
  • Joined: 14-February 08

Re: How to use a MIDI with DirectX?

Posted 22 April 2011 - 10:25 AM

You will notice that whenever you follow a tutorial there are some things that you don't understand and you will have top research them yourself. You can't expect to come out with the exact code you need when the writer of the tutorial clearly intends their work to be a point in the right direction not a code repository.

So your problem is that you couldn't get the event handling working, look up how to do event handling in VB DirectX.

Also how about you post some code as per the rules and then we can start to help you!
Was This Post Helpful? 0
  • +
  • -

#13 Heart's Soul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 12-April 11

Re: How to use a MIDI with DirectX?

Posted 22 April 2011 - 10:31 AM

Right, sorry, I forgot about the code.

    Sub checkforaudio()
        If audi <> lastaudi Then
            lastaudi = audi
            someAudio.Dispose()
            someAudio = Nothing
            If audi = "00" Then
                someAudio = New Audio("SEQ_HALL.mid", False)
            ElseIf audi = "01" Then
                someAudio = New Audio("SEQ_PROTO.mid", False)
            Else
                My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Exclamation)
            End If
            AddHandler someAudio.Ending, AddressOf MusicEnds
            someAudio.Play()
        End If
    End Sub

    Private Sub MusicEnds()
        someAudio.CurrentPosition = 0
    End Sub



audi and lastaudi are there just to keep the system from glitching up and not start playing a song if it is playing already, and the rest is just... there. Hard to explain, really.
Was This Post Helpful? 0
  • +
  • -

#14 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: How to use a MIDI with DirectX?

Posted 22 April 2011 - 11:26 AM

I've been following this thread and it particularly looks like you are expecting others to write your code. You clearly:

1. Have no intention of thoroughly understanding your code.
2. Research specifically the best tools for your application, expecting others to do that for you.
3. Can't be bothered to be more than a cut-and-paste programmer who is surprised when they can't find tailored code on the web.

With this attitude I can reassure you that you will never finish this project because you currently severely lack the analytical skills to get done.

I hope you see the error of your ways and change for the better. I certainly don't waste steam on lazy programmers.
Was This Post Helpful? 0
  • +
  • -

#15 Heart's Soul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 12-April 11

Re: How to use a MIDI with DirectX?

Posted 22 April 2011 - 07:37 PM

View PostButchDean, on 22 April 2011 - 11:26 AM, said:

I've been following this thread and it particularly looks like you are expecting others to write your code. You clearly:

1. Have no intention of thoroughly understanding your code.
2. Research specifically the best tools for your application, expecting others to do that for you.
3. Can't be bothered to be more than a cut-and-paste programmer who is surprised when they can't find tailored code on the web.

This is the hardest thing to reply to.

I want to be able to understand the code, but our teacher does a horrible job of it, and trying to do it yourself without any proper experience before is hard.

I research the best tools for my application, going from un4seen's BASS (only problem is the license), to DirectX, then to WAV music, and back to DirectX. I've worked on this problem for a while before I made this question, and couldn't get an answer that I liked anywhere I searched.

I do cut-and-paste (a very few times, only did that one time for my code and rewrote it later), but I always rewrite the code multiple times to memorize it and I read the description of code (or documentation, if there is any). I'm 15, have only worked with VB .NET for 5 months, and broke my head through to the end. I've read books, tutorials, and the like already. Nothing really helped me.


With this attitude I can reassure you that you will never finish this project because you currently severely lack the analytical skills to get done.

I do have analytical skills, but I find it hard to focus entirely on programming alone at one time.

I hope you see the error of your ways and change for the better. I certainly don't waste steam on lazy programmers.

Your choice.


My replies are in bold.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2