Exemplo n.º 1
0
        public override void OnPortDrivesSignalNoLonger(Signal signal, Port port, int outputIndex)
        {
            if (maskMDrives)
            {
                return;
            }

            bool wasMasked = maskNDrives;

            try
            {
                maskNDrives = true;
                SignalShape ss = _bridge.Signals[signal.InstanceId];
                PortShape   ps = _bridge.Ports[port.InstanceId];
                IConnector  sc = ss.InputConnector;
                IConnector  pc = ps.OutputConnectors[outputIndex];

                IConnection connection = _bridge.Model.ConnectorHolders[pc.AttachedTo] as IConnection;
                sc.DetachConnector(connection.From);
                sc.DetachConnector(connection.To);
                pc.DetachConnector(connection.From);
                pc.DetachConnector(connection.To);
                _bridge.Model.Remove(connection);
            }
            finally
            {
                maskNDrives = wasMasked;
            }
        }
Exemplo n.º 2
0
        public override void OnPortDrivesSignal(Signal signal, Port port, int outputIndex)
        {
            if (maskMDrives)
            {
                return;
            }

            bool wasMasked = maskNDrives;

            try
            {
                maskNDrives = true;
                SignalShape ss = _bridge.Signals[signal.InstanceId];
                PortShape   ps = _bridge.Ports[port.InstanceId];
                IConnector  sc = ss.InputConnector;
                IConnector  pc = ps.OutputConnectors[outputIndex];

                Connection cn = new Connection(Point.Empty, Point.Empty);
                _bridge.Model.AddConnection(cn);
                pc.AttachConnector(cn.From);
                sc.AttachConnector(cn.To);

                ss.Location = new Point(pc.Point.X - 16, pc.Point.Y - 10);
                _bridge.Model.SendToFront(ss);
            }
            finally
            {
                maskNDrives = wasMasked;
            }
        }
Exemplo n.º 3
0
        public override void OnSignalRemoved(Signal signal, int index)
        {
            if (!_bridge.Signals.ContainsKey(signal.InstanceId))
            {
                return;
            }
            SignalShape shape = _bridge.Signals[signal.InstanceId];

            _bridge.Signals.Remove(signal.InstanceId);
            _bridge.Model.RemoveShape(shape);
            _presentation.Invalidate();
        }
Exemplo n.º 4
0
        public override void OnSignalDrivesPort(Signal signal, Port port, int inputIndex)
        {
            SignalShape ss = _bridge.Signals[signal.InstanceId];
            PortShape   ps = _bridge.Ports[port.InstanceId];
            IConnector  sc = ss.OutputConnector;
            IConnector  pc = ps.InputConnectors[inputIndex];

            Connection cn = new Connection(Point.Empty, Point.Empty);

            sc.AttachConnector(cn.From);
            pc.AttachConnector(cn.To);
            _bridge.Model.AddConnection(cn);
        }
Exemplo n.º 5
0
        public override void OnSignalAdded(Signal signal, int index)
        {
            if (_bridge.Signals.ContainsKey(signal.InstanceId))
            {
                return;
            }
            SignalShape shape = new SignalShape(new CommandReference(signal.InstanceId, index));

            shape.Signal   = signal;
            shape.Location = CreateRandomLocation();
            _bridge.Signals.Add(signal.InstanceId, shape);
            _bridge.Model.AddShape(shape);
            _presentation.Invalidate();
        }
 public void Reposition(PortShape shape, Point shift)
 {
     foreach (YttriumConnector c in shape.OutputConnectors)
     {
         foreach (IConnector cnf in c.AttachedConnectors)
         {
             IConnector  c2 = ((IConnection)cnf.Parent).To.AttachedTo;
             SignalShape ss = c2.Parent as SignalShape;
             if (ss != null)
             {
                 ss.Location = new Point(c.Point.X - 16, c.Point.Y - 10);
             }
         }
     }
 }
Exemplo n.º 7
0
        public override void OnPortDrivesSignal(Signal signal, Port port, int outputIndex)
        {
            SignalShape ss = _bridge.Signals[signal.InstanceId];
            PortShape   ps = _bridge.Ports[port.InstanceId];
            IConnector  sc = ss.InputConnector;
            IConnector  pc = ps.OutputConnectors[outputIndex];

            Connection cn = new Connection(Point.Empty, Point.Empty);

            pc.AttachConnector(cn.From);
            sc.AttachConnector(cn.To);
            _bridge.Model.AddConnection(cn);

            ss.Location = new Point(pc.Point.X - 16, pc.Point.Y - 10);
            _bridge.Model.SendToFront(ss);
        }
Exemplo n.º 8
0
        void NetronEntityRemovedHandler(object sender, EntityEventArgs e)
        {
            IDiagramEntity entity = e.Entity;
            SignalShape    ss     = entity as SignalShape;

            if (ss != null)
            {
                if (!_bridge.Signals.ContainsValue(ss))
                {
                    return;
                }
                _bridge.Signals.Remove(ss.SignalReference.InstanceId);
                PostCommandRemoveSignal(ss.SignalReference, true);
                return;
            }
            BusShape bs = entity as BusShape;

            if (bs != null)
            {
                if (!_bridge.Buses.ContainsValue(bs))
                {
                    return;
                }
                _bridge.Buses.Remove(bs.BusReference.InstanceId);
                PostCommandRemoveBus(bs.BusReference);
                return;
            }
            PortShape ps = entity as PortShape;

            if (ps != null)
            {
                if (!_bridge.Ports.ContainsValue(ps))
                {
                    return;
                }
                _bridge.Ports.Remove(ps.PortReference.InstanceId);
                PostCommandRemovePort(ps.PortReference, true);
                return;
            }
            IConnection cn = entity as IConnection;

            if (cn != null)
            {
            }
        }
Exemplo n.º 9
0
        private void Start()
        {
            int sampleRate    = System.Convert.ToInt32(((ListBoxItem)listBoxSampleFreq.SelectedItem).Content);
            int bitsPerSample = System.Convert.ToInt32(((ListBoxItem)listBoxBits.SelectedItem).Content);

            double dB;

            if (!TextBoxDbToDb(out dB))
            {
                MessageBox.Show("エラー: 出力レベルには 数値を半角で入力してください");
                return;
            }

            double freq;

            if (!TextBoxFreqToFreq(out freq))
            {
                MessageBox.Show("エラー: 信号周波数には0.0001以上の数値を半角で入力してください");
                return;
            }
            if (freq < ASIO_FREQ_MIN)
            {
                MessageBox.Show(
                    string.Format("ASIO出力モードでは、信号周波数には{0:0.#}以上の数値を半角で入力してください", ASIO_FREQ_MIN));
                return;
            }

            int seconds = 0;

            if (m_outputMode == OutputMode.WavFile)
            {
                if (!TextBoxSecondsToSeconds(out seconds))
                {
                    MessageBox.Show("エラー: 長さには 0よりも大きい整数を半角で入力してください");
                    return;
                }
            }
            else
            {
                {
                    double freq01 = (double)((int)(freq * 10)) * 0.1;

                    double diff = Math.Abs(freq01 - freq);
                    if (0.00001 < diff)
                    {
                        MessageBox.Show(
                            string.Format("ASIO出力モードでは、都合により0.1Hz以下の周波数を切り捨てます。{0}Hzの波形を出力します。", freq01));
                        freq = freq01;
                    }
                }

                seconds = 1;
                if (((int)(freq * 10) % 10) != 0)
                {
                    seconds = 10;
                }
            }

            SignalShape ss = (SignalShape)listBoxShape.SelectedIndex;

            double trunc = 0;

            if (!TextBoxTruncToTrunc(out trunc))
            {
                MessageBox.Show("エラー: 級数加算打ち切り%には0.0以上の数値を半角で入力してください");
                return;
            }

            SignalGeneraterWorkerArg sgwa;

            sgwa.sgParams.seconds         = seconds;
            sgwa.sgParams.sampleRate      = sampleRate;
            sgwa.sgParams.bitsPerSample   = bitsPerSample;
            sgwa.sgParams.dB              = dB;
            sgwa.sgParams.freq            = freq;
            sgwa.sgParams.ss              = ss;
            sgwa.outputPath               = textBoxOutputFilePath.Text;
            sgwa.sgParams.truncationRatio = trunc * 0.01;
            sgwa.sgParams.amplitude       = (int)(((2 << (sgwa.sgParams.bitsPerSample - 2)) - 1) * Math.Pow(10, sgwa.sgParams.dB / 20.0));
            sgwa.outputMode               = m_outputMode;
            sgwa.outputChannels           = new List <int>();
            for (int i = 0; i < listBoxAsioChannels.Items.Count; ++i)
            {
                ListBoxItem item = listBoxAsioChannels.Items.GetItemAt(i) as ListBoxItem;
                if (item.IsSelected)
                {
                    sgwa.outputChannels.Add(i);
                }
            }

            /*
             *  if (sampleRate <= freq * 2) {
             *      MessageBox.Show("エラー: 信号周波数をサンプリング周波数の半分未満にしてください");
             *      return;
             *  }
             */

            switch (bitsPerSample)
            {
            case 16:
                if (dB < -96.0)
                {
                    MessageBox.Show("エラー: 出力レベルには -96.0以上の数値を入力してください");
                    return;
                }
                break;

            case 24:
                if (dB < -144.0)
                {
                    MessageBox.Show("エラー: 出力レベルには -144.0以上の数値を入力してください");
                    return;
                }
                break;

            default:
                System.Diagnostics.Debug.Assert(false);
                break;
            }

            textBoxLog.Text = "";

            switch (ss)
            {
            case SignalShape.SineWave:
                break;

            case SignalShape.TriangleWave: {
                double harmonics = 0;
                for (int i = 1; ; ++i)
                {
                    harmonics = 2 * i - 1;
                    double level = dB + 20 * Math.Log10(1.0 / harmonics / harmonics);
                    if (harmonics * freq < sampleRate / 2 &&
                        -96.0 < level)
                    {
                    }
                    else
                    {
                        break;
                    }
                }
                if (harmonics <= 5)
                {
                    textBoxLog.Text += string.Format("高調波成分が少ないためあまり三角波っぽい形にはなりません\r\n");
                }
            }
            break;

            case SignalShape.SawToothWaveDesc:
            case SignalShape.SawToothWaveAsc: {
                double harmonics = 0;
                for (int i = 1; ; ++i)
                {
                    harmonics = i;
                    double level = dB + 20 * Math.Log10(1.0 / harmonics);
                    if (harmonics * freq < sampleRate / 2 &&
                        -96.0 < level)
                    {
                    }
                    else
                    {
                        break;
                    }
                }
                if (harmonics <= 5)
                {
                    textBoxLog.Text += string.Format("高調波成分が少ないためあまりのこぎり波っぽい形にはなりません\r\n");
                }
            }
            break;

            case SignalShape.SquareWave: {
                double harmonics = 0;
                for (int i = 1; ; ++i)
                {
                    harmonics = 2 * i - 1;
                    double level = dB + 20 * Math.Log10(1.0 / harmonics);
                    if (harmonics * freq < sampleRate / 2 &&
                        -96.0 < level)
                    {
                        /*
                         * if (harmonics == 1) {
                         *  textBoxLog.Text += string.Format("基本周波数: {1}Hz {2:0.0}dB\r\n", harmonics, harmonics * freq, level);
                         * } else {
                         *  textBoxLog.Text += string.Format("第{0}次高調波: {1}Hz {2:0.0}dB\r\n", harmonics, harmonics * freq, level);
                         * }*/
                    }
                    else
                    {
                        break;
                    }
                }
                if (harmonics <= 5)
                {
                    textBoxLog.Text += string.Format("高調波成分が少ないためあまり矩形波っぽい形にはなりません\r\n");
                }
            }
            break;

            default:
                System.Diagnostics.Debug.Assert(false);
                break;
            }

            buttonStart.IsEnabled = false;
            if (m_outputMode == OutputMode.Asio)
            {
                buttonStop.IsEnabled = true;
            }
            Console.WriteLine("D: MainWindow Start()");
            backgroundWorker1.RunWorkerAsync(sgwa);
        }
Exemplo n.º 10
0
        public override void OnSignalValueChanged(Signal signal)
        {
            SignalShape ss = _bridge.Signals[signal.InstanceId];

            ss.AssignFly(GetFlyweightForSignal(signal.Value));
        }
Exemplo n.º 11
0
        void Model_OnConnectorAttached(object sender, ConnectorsEventArgs e)
        {
            if (maskNDrives)
            {
                return;
            }

            bool wasMasked = maskMDrives;

            try
            {
                maskMDrives = true;

                IConnection con = _bridge.Model.ConnectorHolders[e.SubjectConnector] as IConnection;

                // get rid of uninteresting situations
                if (con != null)
                {
                    if (con.From.AttachedTo == null || con.To.AttachedTo == null)
                    {
                        return;
                    }
                }
                else
                {
                    con = _bridge.Model.ConnectorHolders[e.ObjectConnector] as IConnection;
                    if (con != null)
                    {
                        if (con.From.AttachedTo == null || con.To.AttachedTo == null)
                        {
                            return;
                        }
                    }
                    else
                    {
                        return;
                    }
                }

                // find out who connects to whom
                IConnector portConnector = con.From.AttachedTo;
                IShape     portShape     = (IShape)_bridge.Model.ConnectorHolders[portConnector];
                IShape     valueShape    = (IShape)_bridge.Model.ConnectorHolders[con.To.AttachedTo];

                PortShape port = portShape as PortShape;
                if (port == null)
                {
                    port = valueShape as PortShape;
                    if (port == null)
                    {
                        return;
                    }
                    valueShape    = portShape; //ensure valueShape should now be either signal or bus
                    portConnector = con.To.AttachedTo;
                }
                SignalShape signal = valueShape as SignalShape;
                if (signal != null)
                {
                    // PORT <-> SIGNAL

                    int index = -1;
                    List <YttriumConnector> sl = port.InputConnectors;
                    for (int i = 0; i < sl.Count; i++)
                    {
                        if (sl[i] == portConnector)
                        {
                            index = i;
                            break;
                        }
                    }

                    if (index > -1)
                    {
                        PostCommandSignalDrivesPort(signal.SignalReference, port.PortReference, index);
                        return;
                    }

                    index = -1;
                    sl    = port.OutputConnectors;
                    for (int i = 0; i < sl.Count; i++)
                    {
                        if (sl[i] == portConnector)
                        {
                            index = i;
                            break;
                        }
                    }

                    if (index > -1)
                    {
                        PostCommandPortDrivesSignal(signal.SignalReference, port.PortReference, index);
                    }

                    return;
                }
                BusShape bus = valueShape as BusShape;
                if (bus != null)
                {
                    // PORT <-> BUS

                    int index = -1;
                    List <YttriumConnector> bl = port.BusConnectors;
                    for (int i = 0; i < bl.Count; i++)
                    {
                        if (bl[i] == portConnector)
                        {
                            index = i;
                            break;
                        }
                    }

                    if (index > -1)
                    {
                        PostCommandBusAttachedToPort(bus.BusReference, port.PortReference, index);
                    }

                    return;
                }
            }
            finally
            {
                maskMDrives = wasMasked;
            }
        }