Пример #1
0
 /// <summary>
 /// New
 /// </summary>
 /// <param name="com">出力先シリアルポート</param>
 /// <param name="port">MIDI ポート (portA=False, portB=True)</param>
 public Midi2RsBridge(ComWrapper com, bool port)
 {
     _comport = com;
     _part    = port;
 }
Пример #2
0
        /// <summary>
        /// ブリッジ開始
        /// </summary>
        private void start()
        {
            try
            {
                // 設定の確認
                if (this.ComPortComboBox.Text == "")
                {
                    throw new ApplicationException(
                              "シリアルポートを設定してください。\n" +
                              "(Select the Serial Out.)"
                              );
                }

                if (this.MidiPortAComboBox.Text == this.MidiPortBComboBox.Text)
                {
                    if (this.MidiPortAComboBox.Text == "")
                    {
                        throw new ApplicationException(
                                  "MIDI ポートを設定してください。\n" +
                                  "(Select the MIDI In.)"
                                  );
                    }
                    else
                    {
                        throw new ApplicationException(
                                  "MIDI ポート A と MIDI ポート B は異なる MIDI ポートを設定してください。\n" +
                                  "(Select the MIDI In Port B different from Port A.)"
                                  );
                    }
                }

                // New & Open
                try
                {
                    // New
                    _com       = new ComWrapper(this.ComPortComboBox.Text);
                    _midiportA = new Midi2RsBridge(_com, false);
                    _midiportB = new Midi2RsBridge(_com, true);

                    // COM Port Open
                    try
                    {
                        _com.Open();
                    }
                    catch
                    {
                        throw new ApplicationException(
                                  "シリアルポート が開けません。\n" +
                                  "(Serial port open is fail.)"
                                  );
                    }

                    var devs = MidiDeviceManager.Default.InputDevices;

                    // MIDI Port A Open
                    if (this.MidiPortAComboBox.Text != "")
                    {
                        try
                        {
                            var midi = (from x in devs
                                        where x.Name == this.MidiPortAComboBox.Text
                                        select x).ToArray();

                            _midiportA.Open(midi[0].CreateDevice());
                        }
                        catch
                        {
                            throw new ApplicationException(
                                      "MIDI ポート A が開けません。\n" +
                                      "(MIDI In Port A open is fail.)"
                                      );
                        }
                    }

                    // MIDI Port B Open
                    if (this.MidiPortBComboBox.Text != "")
                    {
                        try
                        {
                            var midi = (from x in devs
                                        where x.Name == this.MidiPortBComboBox.Text
                                        select x).ToArray();

                            _midiportB.Open(midi[0].CreateDevice());
                        }
                        catch
                        {
                            throw new ApplicationException(
                                      "MIDI ポート B が開けません。\n" +
                                      "(MIDI In Port B open is fail.)"
                                      );
                        }
                    }
                }
                catch (ApplicationException ex)
                {
                    // 中断に伴う後始末
                    _com.Close();
                    _midiportA.Close();
                    _midiportB.Close();

                    throw;
                }
            }
            catch (ApplicationException ex)
            {
                MessageBox.Show(ex.Message, "RSC15toSC88", MessageBoxButtons.OK);
                return;
            }

            // ランプ表示
            this.ComPortLampDisplay.BackColor = Color.LawnGreen;

            if (_midiportA.IsOpen == true)
            {
                this.MidiPortALampDisplay.BackColor = Color.LawnGreen;
            }

            if (_midiportB.IsOpen == true)
            {
                this.MidiPortBLampDisplay.BackColor = Color.LawnGreen;
            }

            // 選択禁止
            this.MidiPortAComboBox.Enabled    = false;
            this.MidiPortBComboBox.Enabled    = false;
            this.ComPortComboBox.Enabled      = false;
            this.ReloadPortlistButton.Enabled = false;

            // ボタン名変更
            this.StartButton.Text = "Stop";

            // 実行中
            _exec = true;
        }