public RepeaterMenu(RepeaterInfo info, BipartiteDeviceGraph graph)
        {
            InitializeComponent();

            List <Channel> channelList = Enum.GetValues(typeof(Channel)).Cast <Channel>().ToList();

            for (int i = 0; i < channelList.Count; i++)
            {
                Channel c = channelList[i];

                TextBlock text = new TextBlock();
                text.Text = c.ToString();
                Grid.SetRow(text, 0);
                Grid.SetColumn(text, i);

                CheckBox checkBox = new CheckBox();
                checkBox.Tag = c;
                Grid.SetRow(checkBox, 1);
                Grid.SetColumn(checkBox, i);
                Binding bindChannel = new Binding("ChannelMask");
                bindChannel.Converter          = new ChannelConverter(info);
                bindChannel.ConverterParameter = (int)c;
                bindChannel.Source             = info;
                checkBox.SetBinding(CheckBox.IsCheckedProperty, bindChannel);

                channels.Children.Add(text);
                channels.Children.Add(checkBox);
            }

            Info        = info;
            DataContext = Info;
            this.graph  = graph;
        }
        private void loadGraph_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.InitialDirectory = DefaultData.SavePath;
            bool?result = fileDialog.ShowDialog();

            if (result == false || result == null)
            {
                return;
            }

            string file     = fileDialog.FileName;
            string filename = file.Replace($@"{DefaultData.SavePath}\", "");

            if (filename.Contains("\\") || !filename.EndsWith(".vac"))
            {
                return;
            }

            GraphMap.Children.Clear();
            try
            {
                Graph = BipartiteDeviceGraph.LoadGraph(file);
                DefaultData.DefaultGraph = filename;
            }
            catch
            {
                GraphMap.Children.Clear();
                Graph = new BipartiteDeviceGraph();
            }
            GC.Collect();
        }
        public DeviceControl(MMDevice device, BipartiteDeviceGraph graph)
        {
            InitializeComponent();


            Device = device;
            Graph  = graph;
            Panel.SetZIndex(this, 1);
            deviceBackground.Background = (device.DataFlow == DataFlow.Capture) ? Brushes.LightGreen : Brushes.PaleVioletRed;
            txtDeviceName.Text          = device.FriendlyName;

            ContextMenu = new ContextMenu();
        }
        public MainWindow()
        {
            InitializeComponent();

            GraphMap = graphCanvas;
            DefaultData.CheckFile();

            SelectedTool = "Hand";

            if (DefaultData.DefaultGraph == null)
            {
                Graph = new BipartiteDeviceGraph();
            }
            else
            {
                Graph = BipartiteDeviceGraph.LoadGraph($@"{DefaultData.SavePath}\{DefaultData.DefaultGraph}");
            }

            isRunning = true;
        }
        public static BipartiteDeviceGraph LoadGraph(string filename)
        {
            BipartiteDeviceGraph graph = new BipartiteDeviceGraph();

            StreamReader reader = new StreamReader(filename);

            Dictionary <string, MMDevice> deviceFromID = new Dictionary <string, MMDevice>();

            //create ID dictionary to get the correct MMDevice
            foreach (MMDevice device in new MMDeviceEnumerator().EnumerateAudioEndPoints(DataFlow.All, DeviceState.All))
            {
                deviceFromID[device.ID] = device;
            }

            if (!int.TryParse(reader.ReadLine(), out int N))
            {
                return(new BipartiteDeviceGraph());
            }

            DeviceControl[] devices = new DeviceControl[N];

            //get array of verteces
            for (int i = 0; i < N; i++)
            {
                try
                {
                    MMDevice device = deviceFromID[reader.ReadLine()];
                    double[] pos    = reader.ReadLine().Split().Select(x => double.Parse(x)).ToArray();

                    DeviceControl control = new DeviceControl(device, graph);
                    control.Left = pos[0];
                    control.Top  = pos[1];
                    MainWindow.GraphMap.Children.Add(control);
                    graph.AddVertex(control);
                    devices[i] = control;
                }
                catch
                {
                    devices[i] = null;
                }
            }

            if (!int.TryParse(reader.ReadLine(), out int M))
            {
                return(new BipartiteDeviceGraph());
            }

            //add edges to graph
            for (int i = 0; i < M; i++)
            {
                int[]         adj  = reader.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
                List <string> data = new List <string>();
                for (int j = 0; j < 8; j++)
                {
                    data.Add(reader.ReadLine());
                }

                DeviceControl capture = devices[adj[0]];
                DeviceControl render  = devices[adj[1]];

                if (capture == null || render == null)
                {
                    continue;
                }

                RepeaterInfo repeater = new RepeaterInfo(capture, render, graph);
                repeater.SetData(data);

                graph.AddEdge(capture, render, repeater);
            }

            reader.Close();

            return(graph);
        }
示例#6
0
        public RepeaterInfo(DeviceControl capture, DeviceControl render, BipartiteDeviceGraph graph)
        {
            captureContext        = new MenuItem();
            captureContext.Header = render.DeviceName;
            captureContext.Click += context_Click;
            capture.ContextMenu.Items.Add(captureContext);

            renderContext        = new MenuItem();
            renderContext.Header = capture.DeviceName;
            renderContext.Click += context_Click;
            render.ContextMenu.Items.Add(renderContext);

            Capture = capture;
            Render  = render;
            Link    = new Line
            {
                Stroke          = Brushes.White,
                StrokeThickness = 2,
            };

            Binding bx1 = new Binding("X")
            {
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                Source = capture
            };

            Link.SetBinding(Line.X1Property, bx1);

            Binding by1 = new Binding("Y")
            {
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                Source = capture
            };

            Link.SetBinding(Line.Y1Property, by1);

            Binding bx2 = new Binding("X")
            {
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                Source = render
            };

            Link.SetBinding(Line.X2Property, bx2);

            Binding by2 = new Binding("Y")
            {
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                Source = render
            };

            Link.SetBinding(Line.Y2Property, by2);

            SamplingRate  = DefaultData.SamplingRate;
            BitsPerSample = DefaultData.BitsPerSample;
            ChannelConfig = DefaultData.ChannelConfig;
            BufferMs      = DefaultData.BufferMs;
            Buffers       = DefaultData.Buffers;
            Prefill       = DefaultData.Prefill;
            ResyncAt      = DefaultData.ResyncAt;
            WindowName    = DefaultData.WindowName;
            Path          = DefaultData.RepeaterPath;

            this.graph = graph;
        }