public TranspositionState(TranspositionState before, int rawInterval, int deltaOctave, _Enum.TranspositionMode mode, int interval) { SlotIndex = before.SlotIndex + rawInterval; SetOctave(before, mode, deltaOctave); SlotIndex = (SlotIndex >= 0) ? SlotIndex % 12 : (SlotIndex + 12) % 12; SetPitch(mode, before, interval); SetAccidental(); SetSlot(); DeltaSlot = int.Parse(Slot) - int.Parse(before.Slot); SetLocationY(); Pitch = (Pitch.Length == 1) ? string.Format("{0}{1}", Pitch, Octave) : string.Format("{0}{1}{2}", Pitch.ToCharArray()[0], Octave, Pitch.ToCharArray()[1]); }
private void SetPitch(_Enum.TranspositionMode mode, TranspositionState before, int interval) { string[] pitches = (from a in Infrastructure.Dimensions.Keys.KeyList where (a.Name == before.Pitch) select a.Scale).Single().Split(',')[interval].Split('-'); if (mode == _Enum.TranspositionMode.Octave) Pitch = before.Pitch; else Pitch = (pitches.Length == 1) ? pitches[0] : (EditorState.TargetAccidental == "f") ? pitches[1] : pitches[0]; }
private void Transpose() { Infrastructure.Dimensions.Keys.Key = SelectedKey; _transpositionLog = new List<TranspositionData>(); TranspositionData data = null; RawInterval = Interval; if (Mode != _Enum.TranspositionMode.Octave) Direction = (RawInterval > 0) ? _Enum.Direction.Up : _Enum.Direction.Down; Interval = (RawInterval < 0) ? RawInterval + 12 : RawInterval; var selectedNotes = new ObservableCollection<Repository.DataService.Note>(Infrastructure.Support.Selection.Notes.OrderBy(p => p.StartTime)); string restoreTargetAccidental = EditorState.TargetAccidental; int cnt = 0; foreach (Repository.DataService.Note note in selectedNotes) { cnt++; try { if (NoteController.IsRest(note)) continue; _before = new TranspositionState(note); if (Mode == _Enum.TranspositionMode.Octave) { EditorState.TargetAccidental = _before.Accidental; } _after = new TranspositionState(_before, RawInterval, DeltaOctave, Mode, Interval); data = AddTranspositionRecord(note, RawInterval, CurrentKey.Name.ToString(CultureInfo.InvariantCulture)); _after.Key = SelectedKey; EA.GetEvent<CommitTransposition>().Publish(new Tuple<Guid, object>(note.Id, _after)); SetValidationIndicators(_before, _after); data = data.AddTranspositionRecord(data, Direction.ToString(), note, _locationValidation, _octaveValidation, _slotValidation, _after.DeltaSlot); _transpositionLog.Add(data); } catch (Exception ex) { Exceptions.HandleException(data != null ? string.Format("{0} {1} This note was not transposed. {2}", note.Pitch, note.StartTime, ex.Message) : string.Format("{0} {1}", cnt, ex.Message)); } } EditorState.TargetAccidental = restoreTargetAccidental; TransData = _transpositionLog; _transpositionLog = null; }
private void SetOctave(TranspositionState before,_Enum.TranspositionMode mode, int deltaOctave) { Octave = before.Octave; if (mode == _Enum.TranspositionMode.Octave) { Octave = Octave + deltaOctave; } else { if (SlotIndex > 11) { Octave++; } else if (SlotIndex < 0) Octave--; } }
private void SetValidationIndicators(TranspositionState before, TranspositionState after) { _locationValidation = (Direction == _Enum.Direction.Up && after.Location_Y > before.Location_Y || Direction == _Enum.Direction.Down && after.Location_Y < before.Location_Y) ? "**" : ""; _octaveValidation = (Direction == _Enum.Direction.Up && after.Octave < before.Octave || Direction == _Enum.Direction.Down && after.Octave > before.Octave || Mode == _Enum.TranspositionMode.Octave && before.Octave == after.Octave) ? "**" : ""; _slotValidation = (Direction == _Enum.Direction.Up && int.Parse(before.Slot) > int.Parse(after.Slot) || Direction == _Enum.Direction.Down && int.Parse(before.Slot) < int.Parse(after.Slot)) ? "**" : ""; }