//============================================================== //Scale Add/Delete partial void RunSaveScaleDialog() { /*guardians*/ if (currentShowScale != null) { WarnUser(this.Localizer["Cannot save the new scale while other scale is in display"]); return; } if (currentSound == 0) { WarnUser(this.Localizer["Cannot save empty scale"]); return; } var selectedNotes = new List <Note>(); foreach (var note in Notes) { if (note.IsChecked) { selectedNotes.Add(note); } } var dialogWindow = new ScaleSaveDialogWindow(selectedNotes.ToArray()); dialogWindow.DataContext = this; var dialogResult = dialogWindow.ShowDialog(); if (dialogResult == true) { /*guardians*/ if (dialogWindow.ScaleName == null) { throw new ArgumentNullException("dialogWindow.ScaleName"); } if (dialogWindow.KeynoteOfChoice == null) { throw new ArgumentNullException("dialogWindow.KeynoteOfChoice"); } string scaleName = dialogWindow.ScaleName; Sound keynoteSound = dialogWindow.KeynoteOfChoice.Sound; Scale newScale = new Scale(scaleName, keynoteSound, currentSound); AdditionalScales.Add(newScale); ScalesAll.Add(newScale); ScalesAll.Sort(new ScalesSorter()); Request_SaveAdditionalScales?.Invoke(AdditionalScales.ToArray()); MessageBox.Show(this.Localizer["Scale successfully saved"]); ClearUI(); } }
partial void DeleteSelectedScale() { if (currentShowScale == null) { WarnUser(this.Localizer["To delete the scale one must first select it"]); return; } var scaleToDelete = currentShowScale; bool itIsBasicScale = default(bool); foreach (var scale in ScalesBasic) { if (Object.ReferenceEquals(scaleToDelete, scale)) { itIsBasicScale = true; break; } } if (itIsBasicScale) { WarnUser(this.Localizer["Cannot delete basic scale"]); return; } var confirmation = MessageBox.Show(this.Localizer["Delete this scale? Are you sure?"], "", MessageBoxButton.YesNo, MessageBoxImage.Question); if (confirmation != MessageBoxResult.Yes) { return; } //Point of no return AdditionalScales.Remove(scaleToDelete); ScalesAll.Remove(scaleToDelete); Request_SaveAdditionalScales?.Invoke(AdditionalScales.ToArray()); MessageBox.Show(this.Localizer["Scale deleted"]); ClearUI(); }
private void FilterAvailableScales() { if (currentSound == 0) { ScalesToShow = ScalesAll.ToArray(); } else { int initialCapacity = ScalesAll.Count >> 1; // equals to ScalesAll.Count / 2 List <Scale> fittingScales = new List <Scale>(initialCapacity); foreach (var scale in ScalesAll) { //The magic of bitwise comparison, if 'currentSound' - set of notes is a subset of a scale, //then at the output of the bitwise 'OR' operation we will get the same scale if ((scale.Sound | currentSound) == scale.Sound) { fittingScales.Add(scale); } } ScalesToShow = fittingScales.ToArray(); } }