Skip to content

Commit

Permalink
note tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
jimomulloy committed May 17, 2024
1 parent 73172c1 commit ddedb19
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public void accept(List<NuMessage> messages) throws InstrumentException {
if (tmIndex > 0) {
synthesisFrame = synthesisToneMap.getTimeFrame(tmIndex);
if (synthesisFrame != null) {
synthesiser.synthesiseChords(synthesisFrame);
synthesiser.synthesiseChords(synthesisFrame, cm);
console.getVisor()
.updateToneMapView(synthesisToneMap, synthesisFrame, this.cell.getCellType()
.toString());
Expand All @@ -350,7 +350,7 @@ public void accept(List<NuMessage> messages) throws InstrumentException {
for (int i = tmIndex + 1; i <= sequence; i++) {
synthesisFrame = synthesisToneMap.getTimeFrame(i);
if (synthesisFrame != null) {
synthesiser.synthesiseChords(synthesisFrame);
synthesiser.synthesiseChords(synthesisFrame, cm);
console.getVisor()
.updateToneMapView(synthesisToneMap, synthesisFrame, this.cell.getCellType()
.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ public void calibrateMetronome(double metronomeStart, double metronomeDistance)
double time = metronomeStart;
while (time <= lastTime) {
beatMap.put(time, -1.0);
LOG.severe(">>CM metro put: " + time);
time += metronomeDistance;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ public class NoteTrack {

int number;
double salience;
boolean chordPending;
List<NoteListElement> notes = new CopyOnWriteArrayList<>();
private NoteListElement quantizeNote;

public NoteTrack(int number) {
this.number = number;
Expand Down Expand Up @@ -357,6 +359,22 @@ public NoteListElement[] getCurrentNotes(double time) {
}
return noteList.toArray(new NoteListElement[noteList.size()]);
}

public void setChordPending(boolean chordPending) {
this.chordPending = chordPending;
}

public boolean isChordPending() {
return this.chordPending;
}

public NoteListElement getQuantizeNote() {
return this.quantizeNote;
}

public void setQuantizeNote(NoteListElement quantizeNote) {
this.quantizeNote = quantizeNote;
}
}

public NoteTracker(ToneMap toneMap) {
Expand Down Expand Up @@ -893,6 +911,10 @@ private void processChordTrack(int trackNumber, ToneTimeFrame toneTimeFrame, Cho
private void addChordNotes(NoteTrack track, NoteListElement quantizeNote, double time,
ChordListElement chordListElement, PitchSet pitchSet, SynthChordParameters synthChordParameters) {
NoteListElement lastNote = track.getLastNote();
double lastNoteEndTime = 0;
if (lastNote != null) {
lastNoteEndTime = lastNote.endTime;
}
NoteListElement[] currentNotes = track.getCurrentNotes(time * 1000);
Set<Integer> currentNoteSet = new HashSet<>();
for (NoteListElement nle : currentNotes) {
Expand All @@ -906,18 +928,23 @@ private void addChordNotes(NoteTrack track, NoteListElement quantizeNote, double

int note = 0;
int octave = 0;
double startTime;
double endTime;
double startTime = 0;
double quantizeStartTime = 0;
double quantizeEndTime = 0;
double endTime = 0;
startTime = chordListElement.getStartTime() * 1000;
endTime = chordListElement.getEndTime() * 1000 + incrementTime;
if (quantizeNote != null) {
startTime = quantizeNote.startTime;
endTime = startTime;
double range = quantizeNote.endTime - quantizeNote.startTime;
endTime += range > 0 ? range * synthChordParameters.chordMeasure : synthChordParameters.chordMeasure * 100;
} else {
startTime = chordListElement.getStartTime() * 1000;
endTime = chordListElement.getEndTime() * 1000 + incrementTime;
NoteListElement trackQuantizeNote = track.getQuantizeNote();
if (trackQuantizeNote == null || trackQuantizeNote.startTime < quantizeNote.startTime) {
track.setQuantizeNote(quantizeNote);
quantizeStartTime = quantizeNote.startTime;
quantizeEndTime = quantizeStartTime;
double range = quantizeNote.endTime - quantizeNote.startTime;
quantizeEndTime += range > 0 ? range * synthChordParameters.chordMeasure
: synthChordParameters.chordMeasure * 100;
}
}

double amplitude = 1.0;

List<Double> camps = new ArrayList<>();
Expand Down Expand Up @@ -964,47 +991,122 @@ public int compare(ChordNote c1, ChordNote c2) {
}
camps.add(amplitude);
cnotes.add(note);
if (synthChordParameters.chordPattern == 0 || synthChordParameters.chordPattern == 1) {
if (synthChordParameters.chordPattern == 0 || synthChordParameters.chordPattern == 1
|| synthChordParameters.chordPattern == 4) {
NoteListElement cnle = new NoteListElement(note, pitchSet.getIndex(note), startTime, endTime, 0, 0,
amplitude, amplitude, amplitude, 0, false, incrementTime);
newNotes.add(cnle);
newNoteSet.add(cnle.note);
}
}
if (synthChordParameters.chordPattern == 0) {
LOG.severe("--SYNTH0: " + time + ", " + startTime + ", " + track.number + ", " + startTime + ", "
+ quantizeNote + ", " + time);
if (!newNotes.stream()
.allMatch(nle -> currentNoteSet.contains(nle.note))) {
LOG.severe("--SYNTH0 X: " + startTime + ", " + currentNotes.length + ", " + newNotes.size());
for (NoteListElement cnle : currentNotes) {
LOG.severe("--SYNTH0 X1 CURR NOTE: " + startTime + ", " + cnle.note + ", " + cnle.startTime
+ ", " + cnle.endTime);
if (cnle.endTime + incrementTime >= startTime) {
cnle.endTime = startTime - incrementTime;
}
}
for (NoteListElement nnle : newNotes) {
LOG.severe("--SYNTH0 X1 ADD NOTE: " + startTime + ", " + nnle.note);
track.addNote(nnle);
if (lastNote != null && lastNote.endTime >= startTime) {
return;
}
// if (lastNote != null && lastNote.endTime >= startTime) {
// return;
// }
}
} else {
if (quantizeNote != null) {
if (quantizeStartTime > 0) {
LOG.severe("--SYNTH0 Y: " + startTime + ", " + currentNotes.length + ", " + newNotes.size());
for (NoteListElement nnle : newNotes) {
for (NoteListElement cnle : currentNotes) {
if (lastNote != null && lastNote.endTime >= startTime) {
LOG.severe("--SYNTH0 Y1 CURR NOTE: " + startTime + ", " + cnle.note + ", " + cnle.startTime
+ ", " + cnle.endTime);
if (lastNote != null && lastNoteEndTime >= startTime) {
if (nnle.note == cnle.note && (cnle.endTime + incrementTime >= nnle.startTime)) {
cnle.endTime = nnle.endTime;
LOG.severe("--SYNTH0 Y2 CURR NOTE: " + startTime + ", " + cnle.note + ", "
+ cnle.startTime
+ ", " + cnle.endTime);
}
} else {
if (nnle.note == cnle.note && (cnle.endTime + incrementTime >= nnle.startTime)) {
cnle.endTime = startTime - incrementTime;
LOG.severe("--SYNTH0 Y3 CURR NOTE: " + startTime + ", " + cnle.note + ", "
+ cnle.startTime
+ ", " + cnle.endTime);
}
}
}
if (lastNote != null && lastNote.endTime < startTime) {
if (lastNote != null && lastNoteEndTime < startTime) {
LOG.severe("--SYNTH0 Y1 ADD NOTE: " + startTime + ", " + nnle.note);
track.addNote(nnle);
}
}
}
}
} else if (synthChordParameters.chordPattern == 4) {
LOG.severe(">>SYNTH: " + time + ", " + startTime + ", " + track.number + ", " + startTime + ", "
+ quantizeNote + ", "
+ track.isChordPending());
if (track.isChordPending() || !newNotes.stream()
.allMatch(nle -> currentNoteSet.contains(nle.note))) {

LOG.severe(">>SYNTH X: " + startTime + ", " + currentNotes.length + ", " + newNotes.size());
if (quantizeStartTime > 0) {
track.setChordPending(false);
for (NoteListElement nnle : newNotes) {
nnle.startTime = quantizeStartTime;
track.addNote(nnle);
LOG.severe(">>SYNTH X1 ADD NOTE: " + startTime + ", " + nnle.note);
// if (lastNote != null && lastNote.endTime >= startTime) {
// return;
// }
}
for (NoteListElement cnle : currentNotes) {
LOG.severe(">>SYNTH X1 CURR NOTE: " + startTime + ", " + cnle.note + ", " + cnle.startTime
+ ", " + cnle.endTime);
cnle.endTime = quantizeStartTime - incrementTime;
}
} else {
track.setChordPending(true);
}
} else {
LOG.severe(">>SYNTH Y: " + startTime + ", " + currentNotes.length + ", " + newNotes.size());
if (quantizeStartTime > 0) {
for (NoteListElement nnle : newNotes) {
for (NoteListElement cnle : currentNotes) {
LOG.severe(">>SYNTH Y1 CURR NOTE: " + startTime + ", " + cnle.note + ", " + cnle.startTime
+ ", " + cnle.endTime);
if (lastNote != null && lastNoteEndTime >= startTime) {
if (nnle.note == cnle.note && (cnle.endTime + incrementTime >= nnle.startTime)) {
cnle.endTime = nnle.endTime;
}
} else {
if (nnle.note == cnle.note && (cnle.endTime + incrementTime >= nnle.startTime)) {
cnle.endTime = nnle.startTime - incrementTime;
}
}
}
if (lastNote != null && lastNoteEndTime < startTime) {
LOG.severe(">>SYNTH Y1 ADD NOTE: " + startTime + ", " + nnle.note);
track.addNote(nnle);
}
}
} else {
for (NoteListElement cnle : currentNotes) {
LOG.severe(">>SYNTH Z1 CURR NOTE: " + startTime + ", " + cnle.note + ", " + cnle.startTime
+ ", " + cnle.endTime);
cnle.endTime = endTime - incrementTime;// + incrementTime;
LOG.severe(">>SYNTH Z2 CURR NOTE: " + startTime + ", " + cnle.note + ", " + cnle.startTime
+ ", " + cnle.endTime + ", " + cnle.avgAmp + ", " + cnle);
}
}
}
} else if (synthChordParameters.chordPattern == 1) {
for (NoteListElement nnle : newNotes) {
if (!currentNoteSet.contains(nnle.note)) {
Expand All @@ -1017,6 +1119,7 @@ public int compare(ChordNote c1, ChordNote c2) {
}
}
}

} else {
lastNote = track.getLastNote();
if (synthChordParameters.chordInvert) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ public void synthesiseNotes(ToneTimeFrame toneTimeFrame, CalibrationMap calibrat
if (toneTimeFrame.getChord() == null) {
toneTimeFrame.setChord(chord);
}
// if (chord != null) {
// chord = quantizeChord(chord, calibrationMap, quantizeBeatNote, quantizeRange,
// quantizePercent,
// quantizeBeat);
// }
if (chord != null && quantizeSource == 1) {
chord = quantizeChord(chord, calibrationMap, quantizeBeatNote, quantizeRange,
quantizePercent,
quantizeBeat);
}
}
Set<NoteListElement> discardedNotes = new HashSet<>();
Set<NoteListElement> nles = addNotes(toneTimeFrame);
Expand All @@ -113,7 +113,10 @@ public void synthesiseNotes(ToneTimeFrame toneTimeFrame, CalibrationMap calibrat
}
}

public void synthesiseChords(ToneTimeFrame toneTimeFrame) {
public void synthesiseChords(ToneTimeFrame toneTimeFrame, CalibrationMap calibrationMap) {
NoteTrack quantizeBeatTrack = toneMap.getNoteTracker()
.getBeatTrack(quantizeSource);
NoteListElement quantizeBeatNote = quantizeBeatTrack.getLastNote();
ChordListElement chord = toneTimeFrame.getChord();
if (!synthChordFirstSwitch) {
if (chord != null) {
Expand All @@ -126,6 +129,11 @@ public void synthesiseChords(ToneTimeFrame toneTimeFrame) {
toneTimeFrame.setChord(chord);
chord = toneTimeFrame.getChord();
}
if (chord != null && quantizeSource == 1) {
chord = quantizeChord(chord, calibrationMap, quantizeBeatNote, quantizeRange,
quantizePercent,
quantizeBeat);
}
}

ChordListElement ac = chord;
Expand Down

0 comments on commit ddedb19

Please sign in to comment.