Ejemplo n.º 1
0
 static void Main(string[] args)
 {
     Musician[] Array = new Musician[3];
     Array[0] = new ViolinPlayer();  // 왼쪽은 뮤지션객체, 오른쪽은 바이올린객체인데 오류가 안뜬다.
     Array[1] = new PianoPlayer();
     Array[2] = new FlutePlayer();
     for (int i = 0; i < Array.Length; ++i)
     {
         Array[i].Name();
         Array[i].Instruments();
         Console.WriteLine("********************");
     }
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Song song = SongLoader.Load("..\\..\\..\\..\\songs\\moonlight_sonata.mid");

            Console.WriteLine("Starting Server");

            ConcurrentDictionary <PianoKey, byte> pressedKeys = new ConcurrentDictionary <PianoKey, byte>();

            var pianoPlayer = new PianoPlayer();

            Task.Run(() =>
            {
                var pipe        = new NamedPipeServerStream(Connection.ConnectionString, PipeDirection.In, 1);
                StreamReader sr = new StreamReader(pipe);
                Console.WriteLine("Waiting for connection....");

                pipe.WaitForConnection();

                //Init deserializer for speed later.
                {
                    PianoKeyPressEvent.Deserialize(new PianoKeyPressEvent(new PianoKey(1, Note.A), true).Serialize());
                }
                Console.WriteLine("Connected");

                while (pipe.IsConnected)
                {
                    var kpe = PianoKeyPressEvent.Deserialize(sr.ReadLine());
                    if (kpe.Pressed)
                    {
                        pressedKeys.AddOrUpdate(kpe.Key, 0, (x, y) => 0);
                    }
                    else
                    {
                        pressedKeys.Remove(kpe.Key, out byte x);
                    }
                }
                Console.WriteLine("Connection closed.");
            });

            using (DisplayWindow visualizer = new DisplayWindow(512, 512, "Piano"))
            {
                visualizer.SoundPlayer = pianoPlayer;
                visualizer.CurrentSong = song;
                visualizer.PressedKeys = pressedKeys;
                visualizer.Run(30, 30);
            }

            Console.ReadKey();
        }