private void incDecNote(MappingViewModel mapping, int step) { var oldBinding = mapping.MidiBinding as NoteMidiDefinition; var keyConverter = new MidiLib.Utils.KeyConverter(); var oldKey = keyConverter.ToKeyIPN(oldBinding.KeyText); int newKey = oldKey + step; mapping.SetBinding(new NoteMidiDefinition(oldBinding.Type, oldBinding.Channel, keyConverter.GetKeyTextIPN(newKey))); }
private bool canApplyMidiRange() { if (!IsGenericMidi) { return(false); } var firstBinding = _mappings.First().MidiBinding; if (firstBinding == null || string.IsNullOrEmpty(firstBinding.Note)) { return(false); } var note = firstBinding.Note; var isCC = note.Contains("CC"); var isNote = note.Contains("Note"); var isCombo = note.Contains("+"); if (isCombo || !(isCC || isNote)) { return(false); } var keyConverter = new MidiLib.Utils.KeyConverter(); int number = 127; string suffix = note.Split('.').Last(); if (isCC) { number = int.Parse(suffix); } else if (isNote) { number = keyConverter.ToKeyIPN(suffix); } int count = _mappings.Count(); if (number + count > 127) { return(false); } return(true); }
/* * Note1: * "Mapping.MidiBinding" comes without type by some reason. * Workaound inspects the types explicitelly * We could use AGenericMidiDefinition.Parse but then we had to generte the string by hand * * Note2: * "Type" is not C#. Its about traktor "in"/"out" * */ private AGenericMidiDefinition incDecGeneric(AGenericMidiDefinition old, int step, IncDecWhat what) { if (old is ComboMidiDefinition) { var specific = (ComboMidiDefinition)old; return(new ComboMidiDefinition( incDecGeneric(specific.MidiDefinition1, step, what), incDecGeneric(specific.MidiDefinition2, step, what))); } // at this stage we always have a channel int old_channel = old.Channel; int new_channel = incDec_channel(old_channel, step, what); if (old is NoteMidiDefinition) { var specific = (NoteMidiDefinition)old; var keyConverter = new MidiLib.Utils.KeyConverter(); int old_value = keyConverter.ToKeyIPN(specific.KeyText); int new_value = incDec_note(old_value, step, what); string new_note = keyConverter.GetKeyTextIPN(new_value); return(new NoteMidiDefinition(old.Type, new_channel, new_note)); } if (old is ControlChangeMidiDefinition) { var specific = (ControlChangeMidiDefinition)old; int new_value = incDec_note(specific.Cc, step, what); return(new ControlChangeMidiDefinition(old.Type, new_channel, new_value)); } // this should never be reached! return(null); }
//////////// private void applyMidiRange() { var templateBinding = _mappings.First().MidiBinding as AGenericMidiDefinition; var isCC = templateBinding is ControlChangeMidiDefinition; var keyConverter = new MidiLib.Utils.KeyConverter(); int number = isCC ? (templateBinding as ControlChangeMidiDefinition).Cc : keyConverter.ToKeyIPN((templateBinding as NoteMidiDefinition).KeyText); AGenericMidiDefinition newBinding; foreach (var m in _mappings) { if (m.MidiBinding != null && m.MidiBinding.Equals(templateBinding)) { continue; } number++; if (isCC) { newBinding = new ControlChangeMidiDefinition(templateBinding.Type, templateBinding.Channel, number); } else { newBinding = new NoteMidiDefinition(templateBinding.Type, templateBinding.Channel, keyConverter.GetKeyTextIPN(number)); } m.SetBinding(newBinding); } analyzeSelection(); updateMenus(); }
private void analyzeSelection(bool allowOverrideNote = false) { var bindings = _mappings.Select(mvm => mvm.MidiBinding).Distinct(); var notes = bindings.Select(b => (b != null) ? b.Note : null).Distinct(); if (IsGenericMidi) { var parts = notes.Select(n => { if (n == null) { return(null); } var ch = n.Substring(0, 4); return(new { Channel = ch, Note = n.Replace(ch + ".", "") }); }); var channels = parts.Select(p => (p != null) ? p.Channel : null).Distinct(); _selectedChannels = channels.Where(c => c != null).OrderBy(c => c).ToList(); _variousChannels = channels.Count() > 1; if (!_variousChannels && String.IsNullOrEmpty(_channel)) { setChannel(channels.Single()); } notes = parts.Select(p => (p != null) ? p.Note : null).Distinct(); _selectedNotes = notes.Where(n => n != null).OrderBy(n => n).Cast <object>().ToList(); _allBound = notes.All(n => n != null); _isCCs = _allBound && notes.All(n => n.Contains("CC")); _isNotes = _allBound && notes.All(n => n.Contains("Note")); _hasCombo = _allBound && notes.Any(n => n.Contains("+")); if (_isCCs) { var ccs = notes.Select(n => Int32.Parse(n.Split('.').Last())); _min = ccs.Min(); _max = ccs.Max(); } else if (_isNotes) { var keyConverter = new MidiLib.Utils.KeyConverter(); var keys = notes.Select(n => keyConverter.ToKeyIPN(n.Split('.').Last())); _min = keys.Min(); _max = keys.Max(); } else { _min = 0; _max = 127; } // pestrela: check we can inc/dec the channels var channels2 = channels.Select(n => n.Substring(2, 2)); var channels3 = channels2.Select(n => Int32.Parse(n)); if (_allBound) { _min_ch = channels3.Min(); _max_ch = channels3.Max(); } else { _min_ch = 0; _max_ch = 0; } _variousChannels = channels.Count() > 1; if (!_variousChannels && String.IsNullOrEmpty(_channel)) { setChannel(channels.Single()); } } else { _selectedNotes = _proprietaryDefinitions.Where(n => notes.Contains(n.Note)).DistinctBy(d => d.Note).OrderBy(d => d.Note).Cast <object>().ToList(); } // pestrea: why is this duplicated? _variousNotes = notes.Count() > 1; if (!_variousNotes && (String.IsNullOrEmpty(_note) || allowOverrideNote)) { setNote(notes.Single()); } }