コード例 #1
0
ファイル: SynthManager.cs プロジェクト: ajkolenc/Zentacle
    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);
    }
コード例 #2
0
ファイル: SynthTests.cs プロジェクト: xiejiang2014/midiplayer
 async void stopSong()
 {
     try {
         await Task.Run(() => Synth.Stop());
     } catch (Exception ex) {
         Log.Error(ex.Message);
     }
 }
コード例 #3
0
 static void CleanUp()
 {
     MidiOut.AllPedalsOff();
     MidiOut.AllSoundOff();
     MidiOut.ResetAllControllers();
     MidiINPlugin.DisconnectDevices();
     MidiOUTPlugin.DisconnectDevices();
     Synth.Stop();
 }
コード例 #4
0
ファイル: SynthManager.cs プロジェクト: ajkolenc/Zentacle
 public void ReleaseSynth(Synth s, bool stopSynth = true)
 {
     if (stopSynth)
     {
         s.Stop();
     }
     synthPool.Enqueue(s);
     synthUseHistory.Remove(s);
 }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: xiejiang2014/midiplayer
        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);
            }
        }
コード例 #6
0
ファイル: SynthPlayer.cs プロジェクト: ypm0313/alphaSynth
 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);
 }
コード例 #7
0
ファイル: MainForm.cs プロジェクト: xiejiang2014/midiplayer
        ///////////////////////////////////////////////////////////////////////////////////////////////
        // 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));
            };
        }
コード例 #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();
                }
            };
        }
コード例 #9
0
ファイル: Generator.cs プロジェクト: Lenqth/SoundTest
 private void Generator_FormClosed(object sender, FormClosedEventArgs e)
 {
     synth.Stop();
 }