Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. [Message Deleted]

[Message Deleted]

Scheduled Pinned Locked Moved C#
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hkjghkj1
    wrote on last edited by
    #1

    [Message Deleted]

    C D 3 Replies Last reply
    0
    • H hkjghkj1

      [Message Deleted]

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Depends, have you stepped through it ? Might your midi settings be off ? I know I have a program that uses MIDI, but it doesn't play anything, I can't work out what is wrong with my MIDI settings.

      Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp

      1 Reply Last reply
      0
      • H hkjghkj1

        [Message Deleted]

        D Offline
        D Offline
        DaveyM69
        wrote on last edited by
        #3

        Your code plays fine for me. What OS are you using? You may need to set the correct MIDIOut device in the Sound section in Control Panel. If it's Vista or Weven, it's not there so use my MIDI out setter[^] if needed. Check the volume(s) in your mixer. I belive from the docs (not tested), to loop, you'll need to get notification that it's finished and start it again. You do this by adding " notify" to your command and sending a pointer (could be a hwnd) or a delegate (function pointer) as the last parameter. I think the message you need is MM_MCINOTIFY (0x3B9).

        Dave
        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
        Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
        Why are you using VB6? Do you hate yourself? (Christian Graus)

        1 Reply Last reply
        0
        • H hkjghkj1

          [Message Deleted]

          D Offline
          D Offline
          DaveyM69
          wrote on last edited by
          #4

          I've created a new boilerplate project, pasted and ammended your code. This works - and loops:

          using System;
          using System.IO;
          using System.Runtime.InteropServices;
          using System.Windows.Forms;

          namespace WindowsFormsApplication1
          {
          public partial class Form1 : Form
          {
          public Form1()
          {
          InitializeComponent();
          Shown += new EventHandler(Form1_Shown);
          }

              void Form1\_Shown(object sender, EventArgs e)
              {
                  DoPlay();
              }
          
              private const int MM\_MCINOTIFY = 0x3B9;
          
              \[DllImport("winmm.dll")\]
              private static extern int mciSendString(string lpstrCommand, string lpstrReturnString, uint uReturnLength, IntPtr hwndCallback);
          
              public bool PlayMidiFile(string midiFile) 
              { 
                  if (File.Exists(midiFile)) 
                  { 
                      mciSendString("stop midi", string.Empty, 0, IntPtr.Zero);
                      mciSendString("close midi", string.Empty, 0, IntPtr.Zero);
                      mciSendString("open sequencer!" + midiFile + " alias midi", string.Empty, 0, IntPtr.Zero);
                      int rtn = mciSendString("play midi notify", string.Empty, 0, this.Handle);
                      return (rtn == 0);
                  } 
                  else 
                      return false;
              }
          
              void DoPlay()
              {
                  PlayMidiFile(@"C:\\Windows\\Media\\town.mid");
              }
          
              protected override void WndProc(ref Message m)
              {
                  base.WndProc(ref m);
                  if (m.Msg == MM\_MCINOTIFY)
                      DoPlay();
              }
          }
          

          }

          Dave
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
          Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
          Why are you using VB6? Do you hate yourself? (Christian Graus)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups