private void MessageTypeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { this.Data2TextBox.IsEnabled = MidiChannelEvent.HasData2(this.MessageType); this.EnableOkButton(); this.UpdateData1Text(); this.UpdateData2Text(); }
/*********** * Methods * ***********/ #region Protected Methods protected override bool CheckRequiredInput() { if (!base.CheckRequiredInput()) { return(false); } /* If the event does not use running status, message type and channel are required. */ if (this.RunningStatusCheckBox.IsChecked == false) { if (this.MessageTypeComboBox.SelectedIndex < 0) { return(false); } if (this.Channel < 0) { return(false); } } /* Data byte 1 is always required. Data byte 2 may or may not be, depending on message type. */ if (this.Data1 < 0) { return(false); } if (MidiChannelEvent.HasData2(this.MessageType) && this.Data2 < 0) { return(false); } /* All required input has been provided. */ return(true); }
/// <summary>Returns a comment for the second data byte of a channel message/event.</summary> /// <param name="messageType">Identifies the type of channel message (high nibble of status byte).</param> /// <param name="data">The second data byte of the event.</param> /// <returns>A comment for the data byte.</returns> public static string GetData2Comment(MidiMessageType messageType, int data) { if (!MidiChannelEvent.HasData2(messageType)) { return(null); } string s = (MidiChannelEvent.TypeMap[messageType].DescribeData2 == null) ? null : MidiChannelEvent.TypeMap[messageType].DescribeData2(data, 0, MidiKeySignature.NA); return(MidiChannelEvent.BuildDataComment(MidiChannelEvent.TypeMap[messageType].Data2Name, data, s)); }
/**************** * Constructors * ****************/ #region Public Constructors /// <summary>Initializes a new instance of the MidiEventDialog class.</summary> /// <param name="channelEvent"> /// MidiChannelEvent object representing the MIDI channel message/event to edit, or null to create a new one. /// </param> public MidiChannelEventDialog(MidiChannelEvent channelEvent) : base(channelEvent) { int i = this.ControlCount; DockPanel panel1, panel2; /* Initialize the "Running status" check box. */ this.RunningStatusCheckBox = UI.CreateCheckBox(++i, MarginType.Standard, Properties.Resources.RunningStatus, null); this.RunningStatusCheckBox.Checked += this.RunningStatusCheckBox_Checked; this.RunningStatusCheckBox.Unchecked += this.RunningStatusCheckBox_Checked; /* Initialize the "Message type" label. */ this.MessageTypeLabel = UI.CreateLabel(MarginType.Standard, Properties.Resources.MessageType, true); /* Initialize the "Message type" combo box. */ this.MessageTypeComboBox = new ComboBox(); this.MessageTypeComboBox.TabIndex = ++i; this.MessageTypeComboBox.Margin = new Thickness(UI.TripleSpace, UI.HalfSpace, UI.TripleSpace, UI.UnitSpace); foreach (MidiMessageType messageType in MidiChannelEventDialog.MessageTypes) { string s = MidiChannelEvent.GetTypeComment(messageType); this.MessageTypeComboBox.Items.Add(s); } this.MessageTypeComboBox.SelectionChanged += MessageTypeComboBox_SelectionChanged; this.MessageTypeLabel.Target = this.MessageTypeComboBox; /* Initialize the "Channel" label. */ this.ChannelLabel = UI.CreateLabel(MarginType.Standard, Properties.Resources.Channel, true); /* Initialize the "Channel" text box. */ this.ChannelTextBox = new TextBox(); this.ChannelTextBox.TabIndex = ++i; this.ChannelTextBox.Margin = new Thickness(UI.TripleSpace, UI.HalfSpace, UI.TripleSpace, UI.UnitSpace); this.ChannelTextBox.TextAlignment = TextAlignment.Right; this.ChannelTextBox.GotFocus += UI.TextBox_GotFocus; this.ChannelTextBox.TextChanged += this.ChannelTextBox_TextChanged; this.ChannelLabel.Target = this.ChannelTextBox; /* Initialize the "Data 1" controls. */ this.Data1Label = UI.CreateLabel(MarginType.Standard, Properties.Resources.Data1, true); panel1 = MidiEventDialog.CreateDataBytePanel(ref this.Data1TextBox, ref this.Data1TextBlock, ++i); this.Data1TextBox.TextChanged += this.Data1TextBox_TextChanged; this.Data1Label.Target = this.Data1TextBox; /* Initialize the "Data 2" controls. */ this.Data2Label = UI.CreateLabel(MarginType.Standard, Properties.Resources.Data2, true); panel2 = MidiEventDialog.CreateDataBytePanel(ref this.Data2TextBox, ref this.Data2TextBlock, ++i); this.Data2TextBox.TextChanged += this.Data2TextBox_TextChanged; this.Data2Label.Target = this.Data2TextBox; /* Build out the window and its content. */ this.AddUIElement(this.RunningStatusCheckBox); this.AddUIElement(this.MessageTypeLabel); this.AddUIElement(this.MessageTypeComboBox); this.AddUIElement(this.ChannelLabel); this.AddUIElement(this.ChannelTextBox); this.AddUIElement(this.Data1Label); this.AddUIElement(panel1); this.AddUIElement(this.Data2Label); this.AddUIElement(panel2); this.BuildOut(MidiChannelEventDialog.ClientWidth, MidiChannelEventDialog.TitleString); /* The OK button should start out disabled and stay that way until all required input is entered. */ this.OkButton.IsEnabled = false; /* If a MidiChannelEvent object was supplied, use it to set initial values. */ if (this.ForNewItem) { return; } this.DeltaTime = channelEvent.DeltaTime; this.RunningStatusCheckBox.IsEnabled = false; this.RunningStatusCheckBox.IsChecked = channelEvent.RunningStatus; this.MessageTypeComboBox.SelectedItem = MidiChannelEvent.GetTypeComment(channelEvent.MessageType); this.ChannelTextBox.Text = channelEvent.Channel.ToString(); this.Data1TextBox.Text = channelEvent.Data1.ToString(); if (!MidiChannelEvent.HasData2(channelEvent.MessageType)) { return; } this.Data2TextBox.Text = channelEvent.Data2.ToString(); }
/*********** * Methods * ***********/ #region Public Methods /// <summary>Returns the number of bytes required to store an item of this type.</summary> public static int SizeItem(int deltaTime, bool runningStatus, MidiMessageType messageType) { return(Midi.SizeVLQ(deltaTime) + (runningStatus ? 0 : 1) + (MidiChannelEvent.HasData2(messageType) ? 2 : 1)); }