コード例 #1
0
ファイル: PianoPlayer.cs プロジェクト: moss-oliver/Hero
 public void PlaySound(PianoKey key)
 {
     if (soundDict.TryGetValue(key, out CachedSound sound))
     {
         AddMixerInput(new CachedSoundSampleProvider(sound));
     }
 }
コード例 #2
0
ファイル: PianoPlayer.cs プロジェクト: moss-oliver/Hero
        public PianoPlayer(int sampleRate = 44100, int channelCount = 2)
        {
            foreach (string filename in System.IO.Directory.EnumerateFiles("..\\..\\..\\..\\samples"))
            {
                //var components = filename
                var nameComponents = System.IO.Path.GetFileName(filename).Split('.');

                if ((!filename.Contains("-old")) && nameComponents[1] == "pp")
                {
                    var noteInfo = nameComponents[2];
                    var key      = PianoKey.Parse(noteInfo);
                    if (key != null)
                    {
                        key = new PianoKey(key.Octave + 1, key.Note);
                        var ar = new CachedSound(filename);

                        soundDict.Add(key, ar);
                    }
                }
            }

            Console.WriteLine("Loaded sounds.");

            outputDevice    = new DirectSoundOut(60);
            mixer           = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(sampleRate, channelCount));
            mixer.ReadFully = true;
            outputDevice.Init(mixer);
            outputDevice.Play();
        }
コード例 #3
0
 public PianoKeyPressEvent(PianoKey Key, bool Pressed)
 {
     this.Key     = Key;
     this.Pressed = Pressed;
 }