2011-02-27 40 views
3

我目前正在实施我的最后一年项目作为音乐软件开发的学生。 我正在制作一个播放过程中早期生成的MIDI音轨的软件。VS2010 C#函数使用循环

在我的界面中,有一个按钮“播放”和一个按钮“停止”。 当我点击“播放”时,会播放一个播放此曲目的循环。在这个循环中,我从另一个类的实例中调用一个函数。

我想要的是,当用户按下“暂停”时,循环会暂时停止,当他再次按下“暂停”时,它会回到它在循环中的确切位置。

到目前为止,当我按下播放键,曲目播放正是我想要的,但我不能用我的窗口的任何其他元素,直到环没有完全地处理。

这是我的代码。

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); 
     } 

谢谢你的帮忙。 格雷格

+0

我“不会去真正推荐这个,而是抛出一个'应用。的DoEvents();'在你的程序调用可能会帮助这可能是一个更好的办法是在一个工作线程,虽然 – 2011-02-27 16:41:21

+0

这是什么都与异步CTP做打。? – 2011-02-27 16:47:54

回答