public IScale GetScale(INote note, Scales type) { var definition = this.definitions.FirstOrDefault(d => d.Equals(type)); if (definition == null) { throw new Exception($"Impossible to find scale of type {type}"); } // get the notes. var notes = this.NoteService.GetNotes(); // create the scale :) var scale = new Scale(); scale.ScaleDefinition = definition.DeepClone(); scale.Key = note.DeepClone(); scale.Notes = new List <INote>() { scale.Key }; // work way up. for (var i = 0; i < definition.DistancePatternInSemiTones.Count; i++) { var previous = scale.Notes.Last(); var nextNoteInScale = this.NoteIntervalService.NextNote(notes, previous, definition.DistancePatternInSemiTones[i]); scale.Notes.Add(nextNoteInScale); } return(scale); }
public IChord GetChord(INote note, IChordDefinition definition) { var noteIntervals = NoteIntervalService.GetNoteIntervals(note); var notes = definition.SemiTones.Select(st => { var safe = SafeSemiTone(st); var interval = noteIntervals.First(ni => ni.Interval.DistanceInSemiTones == safe); return(interval.Note.DeepClone()); }).ToList(); return(new Chord { Key = note.DeepClone(), ChordDefinition = definition.DeepClone(), Notes = notes }); }
public IList <INoteInterval> GetNoteIntervals(INote note) { var intervals = this.IntervalService.GetIntervals(); var notes = this.NoteService.GetNotes(); var ret = intervals.Aggregate(new List <INoteInterval>(), (prev, interval) => { var previous = prev.LastOrDefault(); var intervalNote = previous == null ? note.DeepClone() : GetNextNote(notes, previous.Note); prev.Add(new NoteInterval { Note = intervalNote, Interval = interval }); return(prev); }); return(ret); }
protected IInstrumentString CreateString(IList <INote> notes, INote openStringNote, int semiToneCount) { var ret = new InstrumentString(); ret.StringNotes = new List <IInstrumentStringNote>(); ret.OpenStringNote = openStringNote.DeepClone(); for (var i = 1; i <= semiToneCount; i++) { var previousStringNote = ret.StringNotes.LastOrDefault(); var previousNote = previousStringNote?.Note ?? openStringNote; var nextNote = NoteIntervalService.NextNote(notes, previousNote); ret.StringNotes.Add(new StringInstrumentNote { Position = i, Note = nextNote });; } return(ret); }