public MetricSimilarity(MelodySequence seq, IMetric metric, SimilarityType type = SimilarityType.Cosine) { this.metrics = new IMetric[]{metric}; this.target = seq.ToArray(); this.type = type; this.target_metrics = new Dictionary<Pair, float>[] { this.metrics[0].Generate(this.target) }; }
public MetricSimilarity(MelodySequence seq, IMetric[] metrics, SimilarityType type = SimilarityType.Cosine) { this.metrics = metrics; this.target = seq.ToArray(); target_metrics = new Dictionary<Pair, float>[metrics.Length]; this.type = type; for (int i = 0; i < metrics.Length; i++) target_metrics[i] = this.metrics[i].Generate(this.target); }
public CrossCorrelation(MelodySequence seq) { this.target = seq.ToArray(); pitches = new double[this.target.Length]; durations = new double[this.target.Length]; for(int i = 0; i < this.target.Length; i++) { pitches[i] = this.target[i].Pitch; durations[i] = this.target[i].Duration; } highest_peak = GetSimilarity(pitches, pitches, durations, durations); }
public void AddMelody(MelodySequence seq) { Representation.Note[] notes = seq.ToArray(); chain.Add(notes); }
public Note[] GenerateMelody(MelodySequence inputSeq) { SampleSet set = new SampleSet(); var mainNotes = inputSeq.ToArray(); for (int j = INPUT_NOTES; j < mainNotes.Length && j < 200; j++) { Note[] prevNotes = new Note[INPUT_NOTES]; for(int k = 0; k < INPUT_NOTES; k++) { prevNotes[INPUT_NOTES - k-1] = mainNotes[j - k]; } Sample s = GetSample(prevNotes, null); set.Add(s); } List<Note> notes = new List<Note>(); var reverseHashes = Utils.ReverseDictionary(noteHashes); int mainTime = 0; int accompTime = 0; int i = 0; foreach (Sample sample in set) { var res = network.Compute(sample.Inputs); //Note n = new Note((NoteNames)((int)(res[0] * 12)), 6, (Durations)((int)(res[1] * 64.0))); Note n = new Note((int)(res[0] * 128), (int)(res[1] * 64.0)); n.Duration *= 2; n.StandardizeDuration(); if (mainTime >= accompTime) { notes.Add(n); accompTime += (int)n.Duration; } if(i++ % 20 == 0) { notes.Add(new Note(-1, mainTime - accompTime)); } mainTime += (int)(sample.Inputs[1] * 64); } return notes.ToArray(); }
public HarmonySequence GetHarmonySequence(MelodySequence seq) { HarmonySequence sequence = new HarmonySequence(); foreach(Note n in seq.ToArray()) { if (n.Pitch > 0 && n.Velocity > 0 && n.Duration > (int)Durations.en) sequence.AddChord(GetChord(n)); else seq.AddPause(n.Duration); } return sequence; }
public Note[] GenerateMelody(MelodySequence inputSeq) { SampleSet set = new SampleSet(); var mainNotes = inputSeq.ToArray(); for (int j = 0; j < mainNotes.Length && j < 200; j++) { Sample s = GetSample(mainNotes[j],null); set.add(s); } List<Note> notes = new List<Note>(); var reverseHashes = Utils.ReverseDictionary(noteHashes); int mainTime = 0; int accompTime = 0; foreach (Sample sample in set) { var res = ComputeNetworkOutput(sample); //var maxIndex = GetMaxIndex(res); Note outputNote = null; if(res[0] <= 0.05) outputNote = new Note(-1, (int)(res[1] * 64.0),0); else outputNote = new Note((NoteNames)(res[0] * 12), 4, (Durations)(res[1] * 64.0)); outputNote.StandardizeDuration(); notes.Add(outputNote); /* if (reverseHashes.ContainsKey(maxIndex)) { outputNote = reverseHashes[maxIndex]; notes.Add(outputNote); /*accompTime += outputNote.Duration; if (mainTime > accompTime) { notes.Add(new Note(-1, mainTime - accompTime, 0)); accompTime += mainTime - accompTime; } mainTime += (int)(sample.getInput()[1] * 64.0);*/ //} } return notes.ToArray(); }
public void AddMelodySequence(MelodySequence seq) { foreach (Note n in seq.ToArray()) AddNote(n); }
private MelodySequence FixMelodySequence(MelodySequence seq) { var newNotes = new List<Note>(); var notes = seq.ToArray(); if (notes.Length > 1) newNotes.Add(notes[0]); for(int i = 1; i < notes.Length; i++) { bool add = true; var note = notes[i]; var prevNote = notes[i - 1]; if (!note.IsRest()) { if (Math.Abs(note.Pitch - prevNote.Pitch) > 24) { add = false; } } if (add) newNotes.Add(note); } return new MelodySequence(newNotes.ToArray()); }