Beispiel #1
0
    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);
    }
Beispiel #2
0
 async void stopSong()
 {
     try {
         await Task.Run(() => Synth.Stop());
     } catch (Exception ex) {
         Log.Error(ex.Message);
     }
 }
Beispiel #3
0
 static void CleanUp()
 {
     MidiOut.AllPedalsOff();
     MidiOut.AllSoundOff();
     MidiOut.ResetAllControllers();
     MidiINPlugin.DisconnectDevices();
     MidiOUTPlugin.DisconnectDevices();
     Synth.Stop();
 }
Beispiel #4
0
 public void ReleaseSynth(Synth s, bool stopSynth = true)
 {
     if (stopSynth)
     {
         s.Stop();
     }
     synthPool.Enqueue(s);
     synthUseHistory.Remove(s);
 }
Beispiel #5
0
        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);
            }
        }
Beispiel #6
0
 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);
 }
Beispiel #7
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));
            };
        }
Beispiel #8
0
        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();
                }
            };
        }
Beispiel #9
0
 private void Generator_FormClosed(object sender, FormClosedEventArgs e)
 {
     synth.Stop();
 }