Beispiel #1
0
        public IMidiPlayer GetMidiPlayer()
        {
            if (player == null)
            {
                player = new os.MidiPlayer(dataSource);
            }

            return(player);
        }
Beispiel #2
0
        private void Play()
        {
            try {
                TimeSpan now = new TimeSpan(DateTime.Now.Ticks);
                player.Play(now);

                while (player != null && !stopPlaying)
                {
                    lock (playerLock) {
                        if (player.Playing)
                        {
                            player.Update(now);
                            int scrollVal = (int)player.Elapsed.TotalSeconds;
                            if (scrollVal != scrSeek.Value)
                            {
                                SetScrollValue(scrollVal);
                            }
                        }
                        else
                        {
                            if (scrSeek.Value != 0)
                            {
                                SetScrollValue(0);
                            }
                        }
                    }
                    Thread.Sleep(1);
                    now = new TimeSpan(DateTime.Now.Ticks);
                }

                lock (playerLock) {
                    if (player.Playing)
                    {
                        player.Stop();
                        //Console.WriteLine("Closed while playing, stopPlaying: " + stopPlaying + ", player was null: " + (player == null));
                    }
                    else
                    {
                        //Console.WriteLine("Closed due to done playing");
                    }
                }
            }
#if DEBUG
            catch (Exception e) {
                Console.WriteLine("Background thread terminated: " + e.ToString());
            }
#else
            catch {
            }
#endif
            finally {
                player.CloseDevice();
                player = null;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Load a file and start to play
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="format"></param>
        private void LoadFileIntoPlayer()
        {
            StopPlaying();
            stopPlaying = false;

            if (!songtext1.IsValid())
            {
                return;
            }

            StreamReader reader = File.OpenText(songtext1.FileName);

            if (songtext1.Format == SongText.SongFormat.MML)
            {
                var mml = new PlayerMML(outDevice);
                mml.Settings.MaxDuration = TimeSpan.MaxValue;
                mml.Settings.MaxSize     = int.MaxValue;
                mml.Mode = (TextPlayer.MML.MMLMode)Enum.Parse(typeof(TextPlayer.MML.MMLMode), cmbMMLMode.SelectedItem.ToString());
                mml.Load(reader, true);
                player      = mml;
                isLotroSong = null;
            }
            else
            {
                var abc = new PlayerABC(outDevice);
                abc.Settings.MaxDuration = TimeSpan.MaxValue;
                abc.Settings.MaxSize     = int.MaxValue;
                abc.Load(reader);
                isLotroSong         = abc.LotroCompatible;
                abc.LotroCompatible = chkLotroDetect.Checked;
                player = abc;
            }

            // Important, otherwise, impossible to save
            reader.Close();

            player.SetInstrument((MyMidi.Instrument)Enum.Parse(typeof(MyMidi.Instrument), cmbInstruments.SelectedItem.ToString()));
            player.Normalize = chkNormalize.Checked;
            player.Loop      = chkLoop.Checked;
            player.CalculateNormalization();
            SetTimeText();
            scrSeek.Maximum = (int)Math.Ceiling(player.Duration.TotalSeconds);
            scrSeek.Minimum = 0;
            scrSeek.Value   = 0;



            backgroundThread = new Thread(Play);
            backgroundThread.Start();
        }
Beispiel #4
0
        private void LoadFile(StreamReader reader, SongFormat format)
        {
            StopPlaying();
            stopPlaying = false;

            if (format == SongFormat.MML)
            {
                var mml = new PlayerMML();
                mml.Settings.MaxDuration = TimeSpan.MaxValue;
                mml.Settings.MaxSize     = int.MaxValue;
                mml.Mode = (TextPlayer.MML.MMLMode)Enum.Parse(typeof(TextPlayer.MML.MMLMode), cmbMMLMode.SelectedItem.ToString());
                mml.Load(reader);
                player      = mml;
                isLotroSong = null;
            }
            else
            {
                var abc = new PlayerABC();
                abc.Settings.MaxDuration = TimeSpan.MaxValue;
                abc.Settings.MaxSize     = int.MaxValue;
                abc.Load(reader);
                isLotroSong         = abc.LotroCompatible;
                abc.LotroCompatible = chkLotroDetect.Checked;
                player = abc;
            }

            player.SetInstrument((Midi.Instrument)Enum.Parse(typeof(Midi.Instrument), cmbInstruments.SelectedItem.ToString()));
            player.Normalize = chkNormalize.Checked;
            player.Loop      = chkLoop.Checked;
            player.CalculateNormalization();
            SetTimeText();
            scrSeek.Maximum  = (int)Math.Ceiling(player.Duration.TotalSeconds);
            scrSeek.Minimum  = 0;
            scrSeek.Value    = 0;
            backgroundThread = new Thread(Play);
            backgroundThread.Start();
        }