コード例 #1
0
        /// <summary>
        ///     <see cref="_現在選択されているドラム入力種別"/> について、
        ///     <see cref="_変更後のキーバインディング"/> の内容を割り当て済みリストに反映する。
        /// </summary>
        private void _割り当て済みリストを更新する(ListViewItem入力リスト用 選択する項目 = null)
        {
            this.listView割り当て済み入力リスト.Items.Clear();


            // キーボードの反映

            var 現在選択されているドラム入力種別に割り当てられているキーボード入力
                = this._変更後のキーバインディング.キーボードtoドラム.Where((kvp) => (kvp.Value == this._現在選択されているドラム入力種別));

            foreach (var key in 現在選択されているドラム入力種別に割り当てられているキーボード入力)
            {
                this.listView割り当て済み入力リスト.Items.Add(new ListViewItem割り当て済み入力リスト用(InputDeviceType.Keyboard, key.Key));
            }


            // MIDI入力の反映

            var 現在選択されているドラム入力種別に割り当てられているMIDI入力 =
                this._変更後のキーバインディング.MIDItoドラム.Where((kvp) => (kvp.Value == this._現在選択されているドラム入力種別));

            foreach (var note in 現在選択されているドラム入力種別に割り当てられているMIDI入力)
            {
                this.listView割り当て済み入力リスト.Items.Add(new ListViewItem割り当て済み入力リスト用(InputDeviceType.MidiIn, note.Key));
            }


            // 指定された項目があればフォーカスを変更する。

            if (null != 選択する項目)
            {
                foreach (ListViewItem割り当て済み入力リスト用 item in this.listView割り当て済み入力リスト.Items)
                {
                    if (item.deviceType == 選択する項目.deviceType &&
                        item.idKey.deviceId == 選択する項目.inputEvent.DeviceID &&
                        item.idKey.key == 選択する項目.inputEvent.Key)
                    {
                        // MSDNより:
                        // https://msdn.microsoft.com/ja-jp/library/y4x56c0b(v=vs.110).aspx
                        // > 項目をプログラムで選択しても、フォーカスは自動的に ListView コントロールには変更されません。
                        // > そのため、項目を選択するときは、通常、その項目をフォーカスがある状態に設定します。
                        item.Focused  = true;
                        item.Selected = true;
                    }
                }
            }
        }
コード例 #2
0
        public void 表示する()
        {
            using var _ = new LogBlock(Log.現在のメソッド名);

            using var timer = new Timer();

            #region " 設定値で初期化。"
            //----------------
            foreach (ドラム入力種別?drum in Enum.GetValues(typeof(ドラム入力種別)))
            {
                if (!drum.HasValue ||
                    drum == ドラム入力種別.Unknown ||
                    drum == ドラム入力種別.HiHat_Control)
                {
                    continue;   // 除外(設定変更不可)
                }
                this.comboBoxパッドリスト.Items.Add(drum.Value.ToString());
            }

            // 変更後のキーバインディングを、現在の設定値で初期化。
            this._変更後のシステム設定 = Global.App.システム設定.Clone();

            // 最初のパッドを選択し、割り当て済みリストを更新。
            this.comboBoxパッドリスト.SelectedIndex = 0;

            // その他の初期化。
            this._前回の入力リスト追加時刻            = QPCTimer.生カウント相対値を秒へ変換して返す(QPCTimer.生カウント);
            this._FootPedal現在値            = 0;
            this.textBoxFootPedal現在値.Text = "0";
            this.textBoxFootPedal最小値.Text = this._変更後のシステム設定.FootPedal最小値.ToString();
            this.textBoxFootPedal最大値.Text = this._変更後のシステム設定.FootPedal最大値.ToString();
            this._変更あり = false;

            // 初期メッセージを出力。
            this.listView入力リスト.Items.Add($"HID Keyboard の受付を開始しました。");
            for (int i = 0; i < Global.AppForm.MidiIns.DeviceName.Count; i++)
            {
                this.listView入力リスト.Items.Add($"MIDI IN [{i}] '{Global.AppForm.MidiIns.DeviceName[ i ]}' の受付を開始しました。");
            }
            this.listView入力リスト.Items.Add("");
            this.listView入力リスト.Items.Add("* タイミングクロック信号、アクティブ信号は無視します。");
            this.listView入力リスト.Items.Add("* 入力と入力の間が500ミリ秒以上開いた場合は、間に空行を表示します。");
            this.listView入力リスト.Items.Add("");
            this.listView入力リスト.Items.Add("キーボードまたはMIDI信号を入力してください。");
            //----------------
            #endregion

            // タイマーイベントを使って、定期的に、ゲームコントローラ/MIDI入力値の表示と、MIDIフットペダル開度ゲージの描画を行う。
            timer.Interval = 100;
            timer.Tick    += (sender, arg) => {
                #region " ゲームコントローラをポーリングし、入力値を入力リストへ出力。"
                //----------------
                Global.AppForm.GameControllersHID.ポーリングする();

                for (int i = 0; i < Global.AppForm.GameControllersHID.入力イベントリスト.Count; i++)
                {
                    var inputEvent = Global.AppForm.GameControllersHID.入力イベントリスト[i];

                    if (inputEvent.押された)
                    {
                        // 入力リストに表示。
                        var item = new ListViewItem入力リスト用(InputDeviceType.GameController, inputEvent);

                        // 既に割り当てられていたらそのドラム種別を表示。
                        var drumType = this._変更後のシステム設定.ゲームコントローラtoドラム
                                       .Where((kvp) => (kvp.Key.deviceId == item.inputEvent.DeviceID && kvp.Key.key == item.inputEvent.Key))
                                       .Select((kvp) => kvp.Value);
                        if (0 < drumType.Count())
                        {
                            item.Text += $" (現在の割り当て: {drumType.ElementAt( 0 )})";
                        }

                        this._一定時間が経っていれば空行を挿入する();

                        this.listView入力リスト.Items.Add(item);
                        this.listView入力リスト.EnsureVisible(this.listView入力リスト.Items.Count - 1);
                    }
                }
                //----------------
                #endregion

                #region " MIDI入力をポーリングし、入力値を入力リストへ出力。"
                //----------------
                // MidiInChecker の機能もかねて、NoteOFF や ControlChange も表示する。(割り当てはできない。)

                Global.AppForm.MidiIns.ポーリングする();

                for (int i = 0; i < Global.AppForm.MidiIns.入力イベントリスト.Count; i++)
                {
                    var inputEvent = Global.AppForm.MidiIns.入力イベントリスト[i];

                    if (inputEvent.押された && (255 == inputEvent.Key) && (4 == inputEvent.Control))
                    {
                        #region " (A) フットペダルコントロールの場合 → 入力リストではなく専用のUIで表示。"
                        //----------------
                        if (this._FootPedal現在値 != inputEvent.Velocity)
                        {
                            // 現在値
                            this._FootPedal現在値            = inputEvent.Velocity;
                            this.textBoxFootPedal現在値.Text = this._FootPedal現在値.ToString();

                            // 最大値
                            if (this._FootPedal現在値 > this._変更後のシステム設定.FootPedal最大値)
                            {
                                this._変更後のシステム設定.FootPedal最大値 = this._FootPedal現在値;
                                this.textBoxFootPedal最大値.Text = this._変更後のシステム設定.FootPedal最大値.ToString();
                            }

                            // 最小値
                            if (this._FootPedal現在値 <= this._変更後のシステム設定.FootPedal最小値)
                            {
                                this._変更後のシステム設定.FootPedal最小値 = this._FootPedal現在値;
                                this.textBoxFootPedal最小値.Text = this._変更後のシステム設定.FootPedal最小値.ToString();
                            }
                        }
                        //----------------
                        #endregion
                    }
                    else
                    {
                        #region " (B) その他のMIDI入出力 → 入力リストに表示。"
                        //----------------
                        var item = new ListViewItem入力リスト用(InputDeviceType.MidiIn, inputEvent);

                        // 既に割り当てられていたらそのドラム種別を表示。
                        var drumType = this._変更後のシステム設定.MIDItoドラム
                                       .Where((kvp) => (kvp.Key.deviceId == item.inputEvent.DeviceID && kvp.Key.key == item.inputEvent.Key))
                                       .Select((kvp) => kvp.Value);
                        if (0 < drumType.Count())
                        {
                            item.Text += $" (現在の割り当て: {drumType.ElementAt( 0 )})";
                        }

                        this._一定時間が経っていれば空行を挿入する();

                        this.listView入力リスト.Items.Add(item);
                        this.listView入力リスト.EnsureVisible(this.listView入力リスト.Items.Count - 1);
                        //----------------
                        #endregion
                    }
                }
                //----------------
                #endregion

                #region " MIDIフットペダルの開度ゲージを描画。"
                //----------------
                using (var g = pictureBoxFootPedal.CreateGraphics())
                {
                    var 全体矩形    = pictureBoxFootPedal.ClientRectangle;
                    var 背景色     = new System.Drawing.SolidBrush(pictureBoxFootPedal.BackColor);
                    var 最大値ゲージ色 = System.Drawing.Brushes.LightBlue;
                    var ゲージ色    = System.Drawing.Brushes.Blue;

                    g.FillRectangle(背景色, 全体矩形);

                    int 最大値用差分   = (int)(全体矩形.Height * (1.0 - this._変更後のシステム設定.FootPedal最大値 / 127.0));
                    var 最大値ゲージ矩形 = new System.Drawing.Rectangle(
                        全体矩形.X,
                        全体矩形.Y + 最大値用差分,
                        全体矩形.Width,
                        全体矩形.Height - 最大値用差分);
                    g.FillRectangle(最大値ゲージ色, 最大値ゲージ矩形);

                    int 現在値用差分 = (int)(全体矩形.Height * (1.0 - this._FootPedal現在値 / 127.0));
                    var ゲージ矩形  = new System.Drawing.Rectangle(
                        全体矩形.X,
                        全体矩形.Y + 現在値用差分,
                        全体矩形.Width,
                        全体矩形.Height - 現在値用差分);
                    g.FillRectangle(ゲージ色, ゲージ矩形);
                }
                //----------------
                #endregion
            };

            this.KeyPreview = true;            // Control への入力を先に Form が受け取れるようにする。

            this.KeyDown += (sender, arg) => { // ダイアログで RawInput を使う方法が分からないので KeyDown を使う
                #region " キーボードの入力値を入力リストへ出力。"
                //----------------
                var inputEvent = new InputEvent()
                {
                    DeviceID  = 0,
                    Key       = (int)arg.KeyCode,
                    TimeStamp = 0,
                    Velocity  = 100,
                    押された      = true,
                    Control   = 0,
                };

                var item = new ListViewItem入力リスト用(InputDeviceType.Keyboard, inputEvent);

                if (inputEvent.Key == (int)Keys.Escape)      // 割り当てされてほしくないキーはここへ。
                {
                    item.割り当て可能 = false;
                }

                // 既に割り当てられていたらそのドラム種別を表示。
                var drumType = this._変更後のシステム設定.キーボードtoドラム
                               .Where((kvp) => (kvp.Key.deviceId == item.inputEvent.DeviceID && kvp.Key.key == item.inputEvent.Key))
                               .Select((kvp) => kvp.Value);

                if (0 < drumType.Count())
                {
                    item.Text += $" (現在の割り当て: {drumType.ElementAt( 0 )})";
                }

                this._一定時間が経っていれば空行を挿入する();

                this.listView入力リスト.Items.Add(item);
                this.listView入力リスト.EnsureVisible(this.listView入力リスト.Items.Count - 1);
                //----------------
                #endregion
            };

            timer.Start();

            #region " ダイアログを表示。"
            //----------------
            Cursor.Show();

            var dr = this.ShowDialog(Global.AppForm);

            if (Global.AppForm.ScreenMode.IsFullscreenMode)
            {
                Cursor.Hide();
            }
            //----------------
            #endregion

            timer.Stop();

            if (dr == DialogResult.OK)
            {
                // 設定値を反映する。
                Global.App.システム設定 = this._変更後のシステム設定.Clone();
                Global.App.システム設定.保存する();
            }
        }
コード例 #3
0
        public void 表示する()
        {
            using (Log.Block(FDKUtilities.現在のメソッド名))
            {
                // (1) メインウィンドウ用の入力管理をいったん破棄し、このダイアログ用の入力管理を生成する。

                App.入力管理.Dispose();

                using (var 入力管理 = new 入力管理(this.Handle))
                {
                    入力管理.キーバインディングを取得する = () => App.システム設定.キーバインディング;
                    入力管理.キーバインディングを保存する = () => App.システム設定.保存する();
                    入力管理.初期化する();


                    // (2) ダイアログを表示。

                    using (var timer = new Timer())
                    {
                        #region " 設定値で初期化。"
                        //----------------
                        foreach (ドラム入力種別 drum in Enum.GetValues(typeof(ドラム入力種別)))
                        {
                            if (drum == ドラム入力種別.Unknown ||
                                drum == ドラム入力種別.HiHat_Control)
                            {
                                continue;                                   // 除外(設定変更不可)
                            }
                            this.comboBoxパッドリスト.Items.Add(drum.ToString());
                        }

                        // 変更後のキーバインディングを、現在の設定値で初期化。

                        this._変更後のキーバインディング = (キーバインディング)App.システム設定.キーバインディング.Clone();


                        // 最初のパッドを選択し、割り当て済みリストを更新。

                        this.comboBoxパッドリスト.SelectedIndex = 0;


                        // その他の初期化。

                        this._前回の入力リスト追加時刻 = QPCTimer.生カウント相対値を秒へ変換して返す(QPCTimer.生カウント);

                        this._FootPedal現在値 = 0;

                        this.textBoxFootPedal現在値.Text = "0";
                        this.textBoxFootPedal最小値.Text = this._変更後のキーバインディング.FootPedal最小値.ToString();
                        this.textBoxFootPedal最大値.Text = this._変更後のキーバインディング.FootPedal最大値.ToString();

                        this._変更あり = false;


                        // 初期メッセージを出力。

                        this.listView入力リスト.Items.Add($"KEYBOARD \"{入力管理.Keyboard.DeviceName}\" の受付を開始しました。");
                        for (int i = 0; i < 入力管理.MidiIn.DeviceName.Count; i++)
                        {
                            this.listView入力リスト.Items.Add($"MIDI IN [{i}] \"{入力管理.MidiIn.DeviceName[ i ]}\" の受付を開始しました。");
                        }
                        this.listView入力リスト.Items.Add("");
                        this.listView入力リスト.Items.Add("* タイミングクロック信号、アクティブ信号は無視します。");
                        this.listView入力リスト.Items.Add("* 入力と入力の間が500ミリ秒以上開いた場合は、間に空行を表示します。");
                        this.listView入力リスト.Items.Add("");
                        this.listView入力リスト.Items.Add("キーボードまたはMIDI信号を入力してください。");
                        //----------------
                        #endregion

                        // タイマーイベントを使って、定期的に、入力値の表示とフットペダル開度ゲージの描画を行う。
                        timer.Interval = 100;
                        timer.Tick    += (sender, arg) => {
                            #region " キーボードをポーリングし、入力値を入力リストへ出力。"
                            //----------------
                            入力管理.Keyboard.ポーリングする();

                            for (int i = 0; i < 入力管理.Keyboard.入力イベントリスト.Count; i++)
                            {
                                var inputEvent = 入力管理.Keyboard.入力イベントリスト[i];

                                if (inputEvent.押された)
                                {
                                    var item = new ListViewItem入力リスト用(InputDeviceType.Keyboard, inputEvent);

                                    if (inputEvent.Key == (int)Key.Escape)                                          // 割り当てされてほしくないキーはここへ。
                                    {
                                        item.割り当て可能 = false;
                                    }

                                    // 既に割り当てられていたらそのドラム種別を表示。
                                    var drumType = this._変更後のキーバインディング.キーボードtoドラム
                                                   .Where((kvp) => (kvp.Key.deviceId == item.inputEvent.DeviceID && kvp.Key.key == item.inputEvent.Key))
                                                   .Select((kvp) => kvp.Value);
                                    if (0 < drumType.Count())
                                    {
                                        item.Text += $" (現在の割り当て: {drumType.ElementAt( 0 )})";
                                    }

                                    this._一定時間が経っていれば空行を挿入する();

                                    this.listView入力リスト.Items.Add(item);
                                    this.listView入力リスト.EnsureVisible(this.listView入力リスト.Items.Count - 1);
                                }
                                else if (inputEvent.離された)
                                {
                                    // キーボードについては表示しない。
                                }
                            }
                            //----------------
                            #endregion

                            #region " MIDI入力をポーリングし、入力値を入力リストへ出力。"
                            //----------------
                            // MidiInChecker の機能もかねて、NoteOFF や ControlChange も表示する。(割り当てはできない。)

                            入力管理.MidiIn.ポーリングする();

                            for (int i = 0; i < 入力管理.MidiIn.入力イベントリスト.Count; i++)
                            {
                                var inputEvent = 入力管理.MidiIn.入力イベントリスト[i];

                                if (inputEvent.押された && (255 == inputEvent.Key) && (4 == inputEvent.Control))
                                {
                                    #region " (A) フットペダルコントロールの場合 → 入力リストではなく専用のUIで表示。"
                                    //----------------
                                    if (this._FootPedal現在値 != inputEvent.Velocity)
                                    {
                                        // 現在値
                                        this._FootPedal現在値            = inputEvent.Velocity;
                                        this.textBoxFootPedal現在値.Text = this._FootPedal現在値.ToString();

                                        // 最大値
                                        if (this._FootPedal現在値 > this._変更後のキーバインディング.FootPedal最大値)
                                        {
                                            this._変更後のキーバインディング.FootPedal最大値 = this._FootPedal現在値;
                                            this.textBoxFootPedal最大値.Text    = this._変更後のキーバインディング.FootPedal最大値.ToString();
                                        }

                                        // 最小値
                                        if (this._FootPedal現在値 <= this._変更後のキーバインディング.FootPedal最小値)
                                        {
                                            this._変更後のキーバインディング.FootPedal最小値 = this._FootPedal現在値;
                                            this.textBoxFootPedal最小値.Text    = this._変更後のキーバインディング.FootPedal最小値.ToString();
                                        }
                                    }
                                    //----------------
                                    #endregion
                                }
                                else
                                {
                                    #region " (B) その他のMIDI入出力 → 入力リストに表示。"
                                    //----------------
                                    var item = new ListViewItem入力リスト用(InputDeviceType.MidiIn, inputEvent);

                                    // 既に割り当てられていたらそのドラム種別を表示。
                                    var drumType = this._変更後のキーバインディング.MIDItoドラム
                                                   .Where((kvp) => (kvp.Key.deviceId == item.inputEvent.DeviceID && kvp.Key.key == item.inputEvent.Key))
                                                   .Select((kvp) => kvp.Value);
                                    if (0 < drumType.Count())
                                    {
                                        item.Text += $" (現在の割り当て: {drumType.ElementAt( 0 )})";
                                    }

                                    this._一定時間が経っていれば空行を挿入する();

                                    this.listView入力リスト.Items.Add(item);
                                    this.listView入力リスト.EnsureVisible(this.listView入力リスト.Items.Count - 1);
                                    //----------------
                                    #endregion
                                }
                            }
                            //----------------
                            #endregion

                            #region " MIDIフットペダルの開度ゲージを描画。"
                            //----------------
                            using (var g = pictureBoxFootPedal.CreateGraphics())
                            {
                                var 全体矩形    = pictureBoxFootPedal.ClientRectangle;
                                var 背景色     = new System.Drawing.SolidBrush(pictureBoxFootPedal.BackColor);
                                var 最大値ゲージ色 = System.Drawing.Brushes.LightBlue;
                                var ゲージ色    = System.Drawing.Brushes.Blue;

                                g.FillRectangle(背景色, 全体矩形);

                                int 最大値用差分   = (int)(全体矩形.Height * (1.0 - this._変更後のキーバインディング.FootPedal最大値 / 127.0));
                                var 最大値ゲージ矩形 = new System.Drawing.Rectangle(
                                    全体矩形.X,
                                    全体矩形.Y + 最大値用差分,
                                    全体矩形.Width,
                                    全体矩形.Height - 最大値用差分);
                                g.FillRectangle(最大値ゲージ色, 最大値ゲージ矩形);

                                int 現在値用差分 = (int)(全体矩形.Height * (1.0 - this._FootPedal現在値 / 127.0));
                                var ゲージ矩形  = new System.Drawing.Rectangle(
                                    全体矩形.X,
                                    全体矩形.Y + 現在値用差分,
                                    全体矩形.Width,
                                    全体矩形.Height - 現在値用差分);
                                g.FillRectangle(ゲージ色, ゲージ矩形);
                            }
                            //----------------
                            #endregion
                        };

                        timer.Start();

                        #region " ダイアログを表示。"
                        //----------------
                        Cursor.Show();

                        var dr = this.ShowDialog(Program.App);

                        if (App.全画面モード)
                        {
                            Cursor.Hide();
                        }
                        //----------------
                        #endregion

                        timer.Stop();

                        if (dr == DialogResult.OK)
                        {
                            // 設定値を反映する。
                            App.システム設定.キーバインディング = (キーバインディング)this._変更後のキーバインディング.Clone();
                            入力管理.キーバインディングを保存する();
                        }
                    }
                }

                // (3) メインウィンドウ用の入力管理を復活する。

                App.入力管理 = new 入力管理(Program.App.Handle)
                {
                    キーバインディングを取得する = () => App.システム設定.キーバインディング,
                    キーバインディングを保存する = () => App.システム設定.保存する(),
                };
                App.入力管理.初期化する();
            }
        }