3

I am currently implementing my final year project as a Music Software Development student. I am making a software that plays a midi track that is generated earlier in the process.

In my interface, there is a button "play" and a button "stop". When I click "play", a loop is called that plays this track. In this loop, I call a function from an instance of an other class.

What I would like is that when the user press "pause", the loop is temporary stopped, and when he press "pause" again, it goes back exactly where it was in the loop.

So far, when I press play, the track plays exactly how I want to, but I can't use any other element of my window until the loop is not completly processed.

Here is my code.

private void playStopButton_Click(object sender, RoutedEventArgs e)
    {
        // Initialising my output midi devices
        outDevice.Send(new ChannelMessage(ChannelCommand.ProgramChange, information.bassChannel, information.bassSound));//bass
        outDevice.Send(new ChannelMessage(ChannelCommand.ProgramChange, information.guitarChannel, information.guitarSound));//guitar

        for (int barNum = 0; barNum < Globals.numberOfBars; barNum++)
        {
            // playing the first beat
            rythmicPattern.play(0, ref outDevice, information, Globals.chordProgression.Bars[barNum].Chord);

            //second beat
            rythmicPattern.play(1, ref outDevice, information, Globals.chordProgression.Bars[barNum].Chord);

            //thrid beat
            rythmicPattern.play(2, ref outDevice, information, Globals.chordProgression.Bars[barNum].Chord);

            //fourth beat
            rythmicPattern.play(3, ref outDevice, information, Globals.chordProgression.Bars[barNum].Chord);
        }
    }

private void playPauseButton_Click(object sender, RoutedEventArgs e)
        {
            // test if the track is being played
            if (isPlaying)
                rythmicPattern.Pause();
            else
                // if it was already paused, playing back from where I stopped
                rythmicPattern.PlayAfterPause(beatNumber);
        }

Thank you for your help. Greg

2
  • I"m not going to actually recommend this, but throwing an Application.DoEvents(); call in your program might help. It's probably a better idea to play in a worker thread though. Commented Feb 27, 2011 at 16:41
  • What does this have to do with Async CTP? Commented Feb 27, 2011 at 16:47

1 Answer 1

3

You must use threading where you can play the sound in another thread, so you can execute pause method Check this link Multi-threading in .NET: Introduction and suggestions

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.