コード例 #1
0
    void Start()
    {
        config = GetComponent <Config>();
        wave   = GetComponent <SynthWave>();
        player = GetComponent <SynthPlayer>();

        grammar = new Grammar <string>("4B", "4B").
                  AddProduction(new ProductionRule <string>().
                                Input("4B").
                                Output("2B", "2B").
                                SetCondition(Coin)).
                  AddProduction(new ProductionRule <string>().
                                Input("4B").
                                Output("2B", "1B", "1B").
                                SetCondition(Coin)).
                  AddProduction(new ProductionRule <string>().
                                Input("4B").
                                Output("1B", "2B", "1B").
                                SetCondition(Coin)).
                  AddProduction(new ProductionRule <string>().
                                Input("2B").
                                Output("h", "q.", "h", "e", "e", "e", "q").
                                SetCondition(Coin)).
                  AddProduction(new ProductionRule <string>().
                                Input("2B").
                                Output("h.", "q", "e", "e", "q", "h").
                                SetCondition(Coin)).
                  AddProduction(new ProductionRule <string>().
                                Input("1B").
                                Output("h", "q", "q").
                                SetCondition(Coin)).
                  AddProduction(new ProductionRule <string>().
                                Input("1B").
                                Output("q", "q", "q", "q").
                                SetCondition(Coin)).
                  AddProduction(new ProductionRule <string>().
                                Input("1B").
                                Output("h.", "q").
                                SetCondition(Coin));

        _music = null;
    }
コード例 #2
0
        public AlphaSynthWebWorker(SharpKit.Html.workers.WorkerContext main)
        {
            _main = main;
            _main.addEventListener("message", HandleMessage, false);

            _player = new SynthPlayer();

            _player.PositionChanged     += OnPositionChanged;
            _player.PlayerStateChanged  += OnPlayerStateChanged;
            _player.Finished            += OnFinished;
            _player.SoundFontLoad       += OnSoundFontLoad;
            _player.SoundFontLoaded     += OnSoundFontLoaded;
            _player.SoundFontLoadFailed += OnSoundFontLoadFailed;
            _player.MidiLoad            += OnMidiLoad;
            _player.MidiLoaded          += OnMidiLoaded;
            _player.MidiLoadFailed      += OnMidiLoadFailed;
            _player.ReadyForPlay        += OnReadyForPlay;

            OnReady();
        }
コード例 #3
0
        private static void Play()
        {
            //
            // Midi
            Console.WriteLine("Opening Midi");
            string midiFile;
            var    dlg = new OpenFileDialog {
                Filter = "Midi Files (*.mid)|*.mid;*.midi"
            };

            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            byte[] midiData;
            try
            {
                midiData = File.ReadAllBytes(dlg.FileName);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return;
            }

            //
            // SF2
            Console.WriteLine("Opening SF2");
            dlg.Filter = "SoundFont 2 Bank (*.sf2)|*.sf2";
            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            byte[] sf2Data;
            try
            {
                sf2Data = File.ReadAllBytes(dlg.FileName);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return;
            }

            //
            // Creating Synth
            Platform.Platform.OutputFactory = () => new NAudioSynthOutput();
            SynthPlayer player;

            try
            {
                Console.WriteLine("Setup audio");
                player = new SynthPlayer();
                player.LoadMidiBytes(midiData);
                player.LoadSoundFontBytes(sf2Data);
                player.PositionChanged += (sender, args) =>
                {
                    TimeSpan currentTime = TimeSpan.FromMilliseconds(args.CurrentTime);
                    TimeSpan endTime     = TimeSpan.FromMilliseconds(args.EndTime);

                    Console.CursorTop--;
                    Console.Write("".PadLeft(Console.BufferWidth - 1, ' '));
                    Console.CursorLeft = 0;
                    Console.WriteLine("{0:mm\\:ss\\:fff} of {1:mm\\:ss\\:fff} (Tempo {2})",
                                      currentTime, endTime,
                                      player.Sequencer.CurrentTempo);
                };
                player.Finished += (sender, args) => ((NAudioSynthOutput)player.Output).Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return;
            }

            //
            // Play
            Console.WriteLine("Start playing");
            player.Play();

            Console.WriteLine("Press enter to exit");
            while (player.State == SynthPlayerState.Playing)
            {
                try
                {
                    Reader.ReadLine(5000);
                    player.Stop();
                }
                catch (Exception)
                {
                }
            }


            //
            // Cleanup
            player.Stop();
        }
コード例 #4
0
 public void Stop(SynthPlayer synth)
 {
     //synth.Stop(channel);
 }
コード例 #5
0
 public void Play(SynthPlayer synth, WaveType wave, float amplitude, DutyCycle dutyCycle = DutyCycle.Half)
 {
     //channel = synth.Play(WaveType.Square, ToFreq(), 0.2f);
 }
コード例 #6
0
 public void Stop(SynthPlayer synth)
 {
     synth.Stop(waveType, channel);
 }
コード例 #7
0
 public void Play(SynthPlayer synth, WaveType waveType, float amplitude, DutyCycle dutyCycle = DutyCycle.Half)
 {
     this.waveType = waveType;
     channel       = synth.Play(waveType, ToFreq(), amplitude, dutyCycle);
 }