private void SetupBindingCombos() { if (DeviceList.SelectedIndex > -1 && MapsView.SelectedIndices.Count > 0) { MidiMap midiMap = (MidiMap)DeviceList.SelectedItem; ControlBinding binding = (ControlBinding)MapsView.SelectedItems[0].Tag; TargetTypeCombo.Items.Clear(); TargetTypeCombo.Items.AddRange(UiTools.GetBindingTargetTypeList()); TargetTypeCombo.SelectedIndex = (int)binding.TargetType; BindTypeCombo.Items.Clear(); BindTypeCombo.Items.AddRange(Enum.GetNames(typeof(BindingType))); BindTypeCombo.SelectedIndex = (int)binding.BindingType; RepeatCheckbox.Checked = binding.Parent.AutoRepeat; UpdatePropertyCombo(); DeviceImage.Invalidate(); } else { TargetTypeCombo.Items.Clear(); BindTypeCombo.Items.Clear(); TargetPropertyCombo.ClearText(); } }
private static void UpdateDevices() { int count = MidiInput.Count; CloseAllConnections(); int index = 0; foreach (string dev in MidiInput.GetDeviceList()) { if (Maps.ContainsKey(dev)) { MidiMap map = Maps[dev]; int outIndex = MidiOutput.GetDeviceIdByName(dev); map.ConnectDevice(index, outIndex); } else { // Can't find map so create a new default map MidiMap map = new MidiMap(); map.Name = dev; map.Dirty = true; int outIndex = MidiOutput.GetDeviceIdByName(dev); map.ConnectDevice(index, outIndex); map.UpdateMapLinks(); Maps[map.Name] = map; } index++; } MidiSetup.UpdateDeviceList(); MidiInputCount = count; }
private void DeviceImage_Paint(object sender, PaintEventArgs e) { ControlMap selectedMap = null; if (DeviceList.SelectedIndex > -1 && ImageLoaded) { if (MapsView.SelectedIndices.Count > 0) { ControlBinding binding = (ControlBinding)MapsView.SelectedItems[0].Tag; selectedMap = binding.Parent; } SolidBrush BackgroundBrush = new SolidBrush(Color.FromArgb(128, 10, 10, 45)); MidiMap midiMap = (MidiMap)DeviceList.SelectedItem; foreach (ControlMap cm in midiMap.ControlMaps) { if (cm.Mapped) { Brush textBrush = UiTools.StadardTextBrush; if (cm == selectedMap) { textBrush = UiTools.YellowTextBrush; } SizeF sizeText = e.Graphics.MeasureString(cm.Name, UiTools.StandardLarge); Point pnt = ImageToControl(new PointF(cm.X, cm.Y)); pnt.Offset(new Point((int)(-sizeText.Width / 2), (int)(-sizeText.Height / 2))); Point pnt2 = ImageToControl(new PointF(cm.X + cm.Width, cm.Y + cm.Height)); Size size = new Size((int)sizeText.Width, (int)sizeText.Height); e.Graphics.FillRectangle(BackgroundBrush, new Rectangle(pnt, size)); e.Graphics.DrawString(cm.Name, UiTools.StandardLarge, textBrush, pnt); } } BackgroundBrush.Dispose(); } }
private void LoadControlMaps() { MidiMap map = (MidiMap)DeviceList.SelectedItem; MapsView.BeginUpdate(); MapsView.Items.Clear(); foreach (ControlMap cm in map.ControlMaps) { ListViewItem item = new ListViewItem(cm.Name); item.Tag = cm.BindingA; cm.BindingA.Parent = cm; item.SubItems.Add(cm.Channel.ToString()); item.SubItems.Add(cm.ID.ToString()); item.SubItems.Add(cm.BindingA.HadnlerType.ToString()); item.SubItems.Add(cm.BindingA.ToString()); MapsView.Items.Add(item); if (cm.BindingB.HadnlerType != HandlerType.None) { item = new ListViewItem(cm.Name); item.Tag = cm.BindingB; cm.BindingB.Parent = cm; item.SubItems.Add(cm.Channel.ToString()); item.SubItems.Add(cm.ID.ToString()); item.SubItems.Add(cm.BindingB.HadnlerType.ToString()); item.SubItems.Add(cm.BindingB.ToString()); MapsView.Items.Add(item); } } MapsView.EndUpdate(); }
private void DeviceSelected() { LoadControlMaps(); if (DeviceList.SelectedIndex > -1) { MidiMap midiMap = (MidiMap)DeviceList.SelectedItem; SetDeviceImage(midiMap.DeviceImageUrl); } }
public static void SaveMap(MidiMap map, string filename) { var serializer = new XmlSerializer(typeof(MidiMap)); var sw = new StreamWriter(filename); serializer.Serialize(sw, map); sw.Close(); }
void TurnOffMonitoring() { if (monitoringMap != null) { monitoringMap.MessageReceived -= new MIDI.MidiMessageReceived(monitoringMap_MessageReceived); monitoringMap = null; Monitor.Checked = false; } }
public static void SaveMap(MidiMap map, string filename) { XmlSerializer serializer = new XmlSerializer(typeof(MidiMap)); StreamWriter sw = new StreamWriter(filename); serializer.Serialize(sw, map); sw.Close(); }
private void RepeatCheckbox_CheckedChanged(object sender, EventArgs e) { if (DeviceList.SelectedIndex > -1 && MapsView.SelectedIndices.Count > 0) { MidiMap midiMap = (MidiMap)DeviceList.SelectedItem; ControlBinding binding = (ControlBinding)MapsView.SelectedItems[0].Tag; binding.Parent.AutoRepeat = RepeatCheckbox.Checked; } }
private void MapsView_ItemDrag(object sender, ItemDragEventArgs e) { if (DeviceList.SelectedIndex > -1 && MapsView.SelectedIndices.Count > 0) { MidiMap midiMap = (MidiMap)DeviceList.SelectedItem; ControlBinding binding = (ControlBinding)MapsView.SelectedItems[0].Tag; DragSource = binding.Parent; DoDragDrop(MidiControlDataFormat, DragDropEffects.Copy); } }
private void DeviceProperties_Click(object sender, EventArgs e) { if (DeviceList.SelectedIndex > -1) { MidiMap midiMap = (MidiMap)DeviceList.SelectedItem; ControllerProperties props = new ControllerProperties(); props.DeviceMap = midiMap; if (props.ShowDialog() == System.Windows.Forms.DialogResult.OK) { DeviceSelected(); } } }
private void BindTypeCombo_SelectionChanged(object sender, EventArgs e) { if (DeviceList.SelectedIndex > -1 && MapsView.SelectedIndices.Count > 0) { MidiMap midiMap = (MidiMap)DeviceList.SelectedItem; ControlBinding binding = (ControlBinding)MapsView.SelectedItems[0].Tag; binding.BindingType = (BindingType)BindTypeCombo.SelectedIndex; UpdatePropertyCombo(); MapsView.SelectedItems[0].SubItems[4].Text = binding.ToString(); } }
private void PropertyNameText_TextChanged(object sender, EventArgs e) { if (DeviceList.SelectedIndex > -1 && MapsView.SelectedIndices.Count > 0) { MidiMap midiMap = (MidiMap)DeviceList.SelectedItem; ControlBinding binding = (ControlBinding)MapsView.SelectedItems[0].Tag; binding.PropertyName = PropertyNameText.Text; } UpdateSelectedControlMap(); }
private void Delete_Click(object sender, EventArgs e) { if (UiTools.ShowMessageBox(Language.GetLocalizedText(1171, "This will remove this control map. Are you sure you want to do this?"), Language.GetLocalizedText(1172, "Remove Control Map"), MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { MidiMap midiMap = (MidiMap)DeviceList.SelectedItem; ControlBinding binding = (ControlBinding)MapsView.SelectedItems[0].Tag; midiMap.ControlMaps.Remove(binding.Parent); LoadControlMaps(); midiMap.Dirty = true; } }
private void TargetPropertyCombo_SelectionChanged(object sender, EventArgs e) { if (DeviceList.SelectedIndex > -1 && MapsView.SelectedIndices.Count > 0) { MidiMap midiMap = (MidiMap)DeviceList.SelectedItem; ControlBinding binding = (ControlBinding)MapsView.SelectedItems[0].Tag; ScriptableProperty prop = TargetPropertyCombo.SelectedItem as ScriptableProperty; filterLabel.Visible = false; filterList.Visible = false; if (prop != null) { binding.PropertyName = prop.Name; binding.Max = prop.Max; binding.Min = prop.Min; binding.Integer = prop.Type == ScriptablePropertyTypes.Integer; if (binding.BindingType == BindingType.SetValue && prop.Type == ScriptablePropertyTypes.ConstellationFilter) { filterLabel.Visible = true; filterList.Visible = true; filterList.Items.Clear(); int index = 0; int selectedIndex = 0; foreach (string name in ConstellationFilter.Families.Keys) { filterList.Items.Add(name); if (name == binding.Value) { selectedIndex = index; } index++; } filterList.SelectedIndex = selectedIndex; } } else { if (TargetPropertyCombo.SelectedItem is string) { binding.PropertyName = TargetPropertyCombo.SelectedItem.ToString(); } } MapsView.SelectedItems[0].SubItems[4].Text = binding.ToString(); } }
public static void LoadMap(string filename, bool update) { XmlSerializer serializer = new XmlSerializer(typeof(MidiMap)); FileStream fs = new FileStream(filename, FileMode.Open); MidiMap map = (MidiMap)serializer.Deserialize(fs); Maps[map.Name] = map; map.Dirty = true; fs.Close(); map.UpdateMapLinks(); if (update) { UpdateDevices(); } }
private void Save_Click(object sender, EventArgs e) { if (DeviceList.SelectedItem == null) { return; } string device = DeviceList.SelectedItem.ToString(); MidiMap map = (MidiMap)DeviceList.SelectedItem; SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = Language.GetLocalizedText(1170, "WWT MIDI Controller Map (*.wwtmm)|*.wwtmm"); sfd.FileName = device + ".wwtmm"; if (sfd.ShowDialog() == DialogResult.OK) { MidiMapManager.SaveMap(map, sfd.FileName); } }
private void UpdateDeviceListLocal() { //bool itemFound = false; MidiMap device = DeviceList.SelectedItem as MidiMap; DeviceList.BeginUpdate(); DeviceList.Items.Clear(); foreach (MidiMap map in MidiMapManager.Maps.Values) { DeviceList.Items.Add(map); } DeviceList.SelectedItem = device; if (DeviceList.Items.Count > 0 && DeviceList.SelectedIndex == -1) { DeviceList.SelectedIndex = 0; } DeviceList.EndUpdate(); }
private void filterList_SelectionChanged(object sender, EventArgs e) { if (DeviceList.SelectedIndex > -1 && MapsView.SelectedIndices.Count > 0) { MidiMap midiMap = (MidiMap)DeviceList.SelectedItem; ControlBinding binding = (ControlBinding)MapsView.SelectedItems[0].Tag; ScriptableProperty prop = TargetPropertyCombo.SelectedItem as ScriptableProperty; if (prop != null) { if (binding.BindingType == BindingType.SetValue && prop.Type == ScriptablePropertyTypes.ConstellationFilter) { binding.Value = filterList.SelectedItem.ToString(); } } MapsView.SelectedItems[0].SubItems[4].Text = binding.ToString(); } }
private void Monitor_CheckedChanged(object sender, EventArgs e) { if (Monitor.Checked) { if (DeviceList.SelectedIndex > -1) { monitoringMap = (MidiMap)DeviceList.SelectedItem; if (monitoringMap.Connected) { monitoringMap.MessageReceived += new MIDI.MidiMessageReceived(monitoringMap_MessageReceived); return; } else { monitoringMap = null; } } } TurnOffMonitoring(); }
private void DeviceImage_DragDrop(object sender, DragEventArgs e) { string data = e.Data.GetData("Text").ToString(); if (data == MidiControlDataFormat && DragSource != null) { try { MidiMap midiMap = (MidiMap)DeviceList.SelectedItem; DragSource.Mapped = true; PointF pnt = ControlToImage(DeviceImage.PointToClient(new Point(e.X, e.Y))); DragSource.X = pnt.X; DragSource.Y = pnt.Y; DragSource.Width = .1f; DragSource.Height = .1f; DeviceImage.Invalidate(); midiMap.Dirty = true; } catch { } } }
private void UpdatePropertyCombo() { BindingTargetType tt = (BindingTargetType)TargetTypeCombo.SelectedIndex; TargetPropertyCombo.Items.Clear(); TargetPropertyCombo.ClearText(); filterLabel.Visible = false; filterList.Visible = false; if (DeviceList.SelectedIndex > -1 && MapsView.SelectedIndices.Count > 0) { MidiMap midiMap = (MidiMap)DeviceList.SelectedItem; ControlBinding binding = (ControlBinding)MapsView.SelectedItems[0].Tag; binding.TargetType = tt; IScriptable scriptInterface = null; bool comboVisible = true; switch (tt) { case BindingTargetType.Setting: scriptInterface = Settings.Active as IScriptable; break; case BindingTargetType.SpaceTimeController: scriptInterface = SpaceTimeController.ScriptInterface; break; case BindingTargetType.Goto: comboVisible = false; break; case BindingTargetType.Layer: scriptInterface = LayerManager.ScriptInterface; break; case BindingTargetType.Navigation: scriptInterface = Earth3d.MainWindow as IScriptable; break; //case BindingTargetType.Actions: // break; //case BindingTargetType.Key: // break; //case BindingTargetType.Mouse: // break; default: break; } if (comboVisible) { TargetPropertyCombo.Visible = true; PropertyNameText.Visible = false; BindTypeCombo.Visible = true; BindTypeLabel.Visible = true; if (scriptInterface != null) { switch (binding.BindingType) { case BindingType.Action: TargetPropertyCombo.Items.Clear(); TargetPropertyCombo.Items.AddRange(scriptInterface.GetActions()); break; case BindingType.Toggle: TargetPropertyCombo.Items.Clear(); TargetPropertyCombo.Items.AddRange(UiTools.GetFilteredProperties(scriptInterface.GetProperties(), binding.BindingType)); break; case BindingType.SyncValue: TargetPropertyCombo.Items.Clear(); TargetPropertyCombo.Items.AddRange(scriptInterface.GetProperties()); break; case BindingType.SetValue: TargetPropertyCombo.Items.Clear(); TargetPropertyCombo.Items.AddRange(scriptInterface.GetProperties()); break; default: break; } } TargetPropertyCombo.SelectedItem = binding.PropertyName; } else { PropertyNameText.Visible = true; TargetPropertyCombo.Visible = false; PropertyNameText.Text = binding.PropertyName; BindTypeCombo.Visible = false; BindTypeLabel.Visible = false; } MapsView.SelectedItems[0].SubItems[4].Text = binding.ToString(); UpdateSelectedControlMap(); } }
void TurnOffMonitoring() { if (monitoringMap != null) { monitoringMap.MessageReceived -= monitoringMap_MessageReceived; monitoringMap = null; Monitor.Checked = false; } }
private static void UpdateDevices() { var count = MidiInput.Count; CloseAllConnections(); var index = 0; foreach (var dev in MidiInput.GetDeviceList()) { if (Maps.ContainsKey(dev)) { var map = Maps[dev]; var outIndex = MidiOutput.GetDeviceIdByName(dev); map.ConnectDevice(index, outIndex); } else { // Can't find map so create a new default map var map = new MidiMap(); map.Name = dev; map.Dirty = true; var outIndex = MidiOutput.GetDeviceIdByName(dev); map.ConnectDevice(index, outIndex); map.UpdateMapLinks(); Maps[map.Name] = map; } index++; } MidiSetup.UpdateDeviceList(); MidiInputCount = count; }
private void UpdateSelectedControlMap() { MidiMap midiMap = (MidiMap)DeviceList.SelectedItem; midiMap.Dirty = true; }