public static PlayLineHarmony GetResult(ITempoForBars tempo, IBarTemplateModel template, List <Note.Note> noteList, PlayOrderType orderType) { PlayLineHarmony playLine = new PlayLineHarmony(); playLine.Instrument = Sanford.Multimedia.Midi.GeneralMidiInstrument.Accordion; playLine.Order = 1; playLine.Vol = 127; playLine.NoteQueue = new List <PlayLineNotes>(); Random r = new Random(); var repeatRandom = r.Next(0, 19); var minOctav = r.Next(3, 5); var maxOctav = r.Next(5, 7); var skipRandom = r.Next(1, 8); int[] notes = noteList.Where(a => a.Octave >= minOctav && a.Octave <= maxOctav).Skip(skipRandom).Take(template.NoteCount).OrderByDescending(a => a.Number).Select(a => a.Number).ToArray(); if (orderType == PlayOrderType.Ascending) { notes = notes.OrderBy(a => a).ToArray(); } else if (orderType == PlayOrderType.Randomize) { notes = notes.Randomize().Take(notes.Length).ToArray(); } for (int j = 0; j < notes.Length; j++) { var newNote = GetNote(playLine.NoteQueue.Count + 1, tempo, template.AllNoteValues[j].NoteValue, noteList, notes[j]); playLine.NoteQueue.Add(newNote); } return(playLine); }
private static PlayLineNotes GetNote(this NoteValue value, int order, ITempoForBars tempo, List <Note.Note> asNotes, List <Note.Note> deNotes, int noteNumber) { return(new PlayLineNotes() { IsPlayed = false, Length = tempo.LengthByTempo(value), Note = noteNumber != 0 ? asNotes.FirstOrDefault(a => a.Number == noteNumber) : null, Order = order, Silence = false }); }
private void numericTempoValue_ValueChanged(object sender, EventArgs e) { _tempo = new Tempo.Tempo((int)numericTempoValue.Value); switch (comboBoxRythm.SelectedIndex) { case 0: _tempoForBars = _tempo.Tempo4_4; break; case 1: _tempoForBars = _tempo.Tempo3_4; break; default: break; } }
public static double LengthByTempo(this ITempoForBars tempo, NoteValue value) { switch (value) { case NoteValue.Quarter: return(tempo.QuarterLength); case NoteValue.DottedQuarter: return(tempo.DottedQuarterLength); case NoteValue.Half: return(tempo.HalfLength); case NoteValue.Eighth: return(tempo.EighthLength); case NoteValue.DottedEighth: return(tempo.DottedEighthLength); case NoteValue.Sixteenth: return(tempo.SixteenthLength); case NoteValue.DottedSixteenth: return(tempo.DottedSixteenthLength); case NoteValue.ThirtySecond: return(tempo.ThirtySecondLength); case NoteValue.DottedThirtySecond: return(tempo.DottedThirtySecondLength); case NoteValue.SixtyFourth: return(tempo.SixtyFourthLength); case NoteValue.DottedSixtyFourth: return(tempo.DottedSixtyFourthLength); case NoteValue.HundredTwentyEighth: return(tempo.HundredTwentyEighthLength); default: return(0); } }
private void UpdateTempaltes(int index) { switch (_rythmType[index].Value) { case 0: _templates = TempoFor4_4Bars.GetAllAvailableTemplates().ToList(); _tempoForBars = _tempo.Tempo4_4; break; case 1: _templates = TempoFor3_4Bars.GetAllAvailableTemplates().ToList(); _tempoForBars = _tempo.Tempo3_4; break; default: break; } numericTemplates.Maximum = _templates.Count - 1; numericTemplates.Value = 0; }
public abstract PlayLineHarmony Get3_4Templates(ITempoForBars tempo, IBarTemplateModel template, List <Note.Note> noteList, PlayOrderType orderType);
public override PlayLineHarmony Get3_4Templates(ITempoForBars tempo, IBarTemplateModel template, List <Note.Note> noteList, PlayOrderType orderType) { return(GenerateTemplateCreator.GetResult(tempo, template, noteList, orderType)); }
public static PlayLineHarmony GetResult(ITempoForBars tempo, List <Note.Note> noteList, List <IBarTemplateModel> templates) { PlayLineHarmony playLine = new PlayLineHarmony(); playLine.Instrument = Sanford.Multimedia.Midi.GeneralMidiInstrument.Banjo; playLine.Order = 1; playLine.Vol = 127; playLine.NoteQueue = new List <PlayLineNotes>(); Random r = new Random(); templates = templates.OrderBy(a => Guid.NewGuid()).ToList(); for (int i = 0; i < templates.Count(); i++) { var repeatRandom = r.Next(0, 19); var minOctav = r.Next(2, 5); var maxOctav = r.Next(5, 8); var skipRandom = r.Next(1, 8); var template = templates[i]; int[] notes = noteList.Where(a => a.Octave >= minOctav && a.Octave <= maxOctav).Skip(skipRandom).Take(template.NoteCount).OrderByDescending(a => a.Number).Select(a => a.Number).ToArray(); if (repeatRandom >= 17) { notes = notes.OrderBy(a => a).ToArray(); } else if (repeatRandom >= 2) { notes = notes.Randomize().Take(notes.Length).ToArray(); } var repeat = new List <PlayLineNotes>(); for (int j = 0; j < notes.Length; j++) { var newNote = GetNote(playLine.NoteQueue.Count + 1, tempo, template.AllNoteValues[j].NoteValue, noteList, notes[j]); playLine.NoteQueue.Add(newNote); repeat.Add(newNote); } if (repeatRandom > 15) { foreach (var item in repeat) { playLine.NoteQueue.Add(item); } foreach (var item in repeat) { playLine.NoteQueue.Add(item); } } else if (repeatRandom > 12) { foreach (var item in repeat) { playLine.NoteQueue.Add(item); } } if (repeatRandom % 3 == 0) { playLine.NoteQueue.Add(new PlayLineNotes() { IsPlayed = false, Length = tempo.QuarterLength, Note = null, Order = playLine.NoteQueue.Count + 1, Silence = true }); } } return(playLine); }