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