コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: btakacs1/VCCS
        public MainWindow()
        {
            InitializeComponent();

            //Console.WriteLine("Connecting");
            //Client.Connect();
            //Console.WriteLine("Connected");

            waveFormat = new WaveFormat(20000, WaveIn.GetCapabilities(0).Channels);

            sourceStream = new WaveIn();
            sourceStream.DeviceNumber       = 0;
            sourceStream.BufferMilliseconds = 10;
            sourceStream.WaveFormat         = waveFormat;
            sourceStream.DataAvailable     += sourceStream_DataAvailable;

            waveBuffer = new BufferedWaveProvider(waveFormat);

            waveOut = new DirectSoundOut();
            waveOut.Init(waveBuffer);

            sourceStream.StartRecording();

            Client.OnVoiceReceived += (byte[] data) =>
            {
                //waveStream.Write(data, 0, data.Length);
                waveBuffer.AddSamples(data, 0, data.Length);
                waveOut.Play();
            };

            Client.OnConnected += () =>
            {
                Console.WriteLine("RECEIVED CONNECT");
                ConnectButton.Content = Client.Callsign;
                ConnectButton.SetResourceReference(BackgroundProperty, AdonisUI.Brushes.Layer1InteractionBrush);
            };

            Client.OnDisconnected += () =>
            {
                ConnectButton.Content = "CONNECT";
                ConnectButton.SetResourceReference(BackgroundProperty, AdonisUI.Brushes.Layer1BackgroundBrush);
                GetControllerButton(Client.Callsign).SetResourceReference(BackgroundProperty, AdonisUI.Brushes.Layer0BackgroundBrush);
                ForEachControllerButton((Button button) =>
                {
                    button.IsEnabled = false;
                    //button.SetResourceReference(BackgroundProperty, AdonisUI.Brushes.Layer0BackgroundBrush);
                    return(false);
                });
            };

            Client.OnControllerConnected += (string callsign) =>
            {
                GetControllerButton(callsign).IsEnabled = true;
                if (callsign == Client.Callsign)
                {
                    GetControllerButton(callsign).SetResourceReference(BackgroundProperty, AdonisUI.Brushes.Layer1HighlightBrush);
                }
            };

            Client.OnControllerDisconnected += (string callsign) =>
            {
                GetControllerButton(callsign).IsEnabled = false;
            };

            ForEachControllerButton((Button button) =>
            {
                button.Click += (object sender, RoutedEventArgs e) =>
                {
                    Client.ControllerButtonClicked(button.Name.Substring(2));
                };
                return(false);
            });

            defaultButtonBrush = ButtonRingOff.Background;

            buttonFlashTimer.Interval = new TimeSpan(0, 0, 0, 0, 250);
            buttonFlashTimer.Tick    += (object o, EventArgs e) =>
            {
                buttonFlashState = !buttonFlashState;
                foreach (Button button in flashingButtons)
                {
                    if (buttonFlashState)
                    {
                        button.Background = Brushes.Gray;
                    }
                    else
                    {
                        button.Background = defaultButtonBrush;
                    }
                }
            };
            buttonFlashTimer.Start();

            Client.OnIncomingCallAdded += (string callsign) =>
            {
                flashingButtons.Add(GetControllerButton(callsign));
                Console.WriteLine("Added flashing button " + flashingButtons[0].Name);
            };

            Client.OnIncomingCallRemoved += (string callsign) =>
            {
                flashingButtons.Remove(GetControllerButton(callsign));
            };

            Client.OnCallStarted += (string callsign) =>
            {
                ButtonEnd.IsEnabled = true;
                GetControllerButton(callsign).Background = Brushes.Gray;
            };

            Client.OnCallEnded += (string callsign) =>
            {
                ButtonEnd.IsEnabled = false;
                GetControllerButton(callsign).Background = defaultButtonBrush;
            };
        }