public Synth RequestSynth(Synth.WaveType waveType, Synth prefab = null) { Synth requestedSynth = null; if (synthPool.Count == 0 && createdSynths >= SynthLimit && synthUseHistory.Count > 0) { Synth reclaimed = synthUseHistory[synthUseHistory.Count - 1]; reclaimed.Stop(); synthPool.Enqueue(reclaimed); synthUseHistory.RemoveAt(synthUseHistory.Count - 1); } if (synthPool.Count > 0) { Synth recycled = synthPool.Dequeue(); if (prefab != null) { recycled.CustomFile = prefab.CustomFile; recycled.CustomWave = prefab.CustomWave; recycled.Envelope = prefab.Envelope; recycled.SetPitch(prefab.Pitch); recycled.SetVolume(prefab.Volume); } if (recycled.Wave != waveType) { recycled.Wave = waveType; recycled.GenerateClip(); } requestedSynth = recycled; } else { Synth newSynth = null; createdSynths++; if (prefab != null) { newSynth = Instantiate <Synth>(prefab); } else { newSynth = new GameObject(waveType.ToString() + " Synth").AddComponent <Synth>(); newSynth.Wave = waveType; } newSynth.transform.SetParent(transform, false); newSynth.transform.position = Vector3.zero; newSynth.Init(); newSynth.SetPitch((prefab ?? newSynth).Pitch); newSynth.SetVolume(prefab.Volume); requestedSynth = newSynth; } if (requestedSynth != null) { synthUseHistory.Add(requestedSynth); } return(requestedSynth); }
async void stopSong() { try { await Task.Run(() => Synth.Stop()); } catch (Exception ex) { Log.Error(ex.Message); } }
static void CleanUp() { MidiOut.AllPedalsOff(); MidiOut.AllSoundOff(); MidiOut.ResetAllControllers(); MidiINPlugin.DisconnectDevices(); MidiOUTPlugin.DisconnectDevices(); Synth.Stop(); }
public void ReleaseSynth(Synth s, bool stopSynth = true) { if (stopSynth) { s.Stop(); } synthPool.Enqueue(s); synthUseHistory.Remove(s); }
async void stopSong() { try { await Task.Run(() => Synth.Stop()); Invoke((MethodInvoker)(() => { Enumerable.Range(0, Synth.TrackCount).ToList().ForEach(x => { listView.Items[x].SubItems[0].ForeColor = Color.Black; }); })); } catch (Exception ex) { Log.Error(ex.Message); } }
public void Stop() { if (State == SynthPlayerState.Stopped || !IsReady) { return; } Logger.Debug("Stopping playback"); Sequencer.Stop(); Synth.Stop(); Output.Stop(); State = SynthPlayerState.Stopped; OnPlayerStateChanged(new PlayerStateChangedEventArgs(State)); FirePositionChanged(0); }
/////////////////////////////////////////////////////////////////////////////////////////////// // EventHandler void MainForm_Load(object sender, EventArgs e) { Conf.Load(); initializeControl(); Synth.Playbacking += (IntPtr data, IntPtr evt) => { return(Synth.HandleEvent(data, evt)); }; Synth.Started += () => { Log.Info("Started called."); Invoke((MethodInvoker)(() => { Text = $"MidiPlayer: {Synth.MidiFilePath.ToFileName()} {Synth.SoundFontPath.ToFileName()}"; listView.Items.Clear(); Enumerable.Range(0, Synth.TrackCount).ToList().ForEach(x => { listView.Items.Add(new ListViewItem(new string[] { " ●", "--", "--", "--", "--", "--" })); }); })); }; Synth.Ended += () => { Log.Info("Ended called."); if (!playList.Ready) { Synth.Stop(); Synth.Start(); } else { Synth.Stop(); Synth.MidiFilePath = playList.Next; Synth.Start(); } }; Synth.Updated += (object sender, PropertyChangedEventArgs e) => { var _track = (Synth.Track)sender; Invoke(updateList(_track)); }; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); requestPermissions(); Platform.Init(this, savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.activity_main); initializeComponent(); Conf.Load(); Synth.Playbacking += (IntPtr data, IntPtr evt) => { return(Synth.HandleEvent(data, evt)); }; Synth.Started += () => { Log.Info("Started called."); MainThread.BeginInvokeOnMainThread(() => { Title = $"MidiPlayer: {Synth.MidiFilePath.ToFileName()} {Synth.SoundFontPath.ToFileName()}"; }); }; Synth.Ended += () => { Log.Info("Ended called."); if (!playList.Ready) { Synth.Stop(); Synth.Start(); } else { Synth.Stop(); Synth.MidiFilePath = playList.Next; Synth.Start(); } }; }
private void Generator_FormClosed(object sender, FormClosedEventArgs e) { synth.Stop(); }