Skip to content

Commit

Permalink
view update
Browse files Browse the repository at this point in the history
  • Loading branch information
jimomulloy committed Mar 15, 2023
1 parent f20859c commit 0f23e8c
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,9 @@ public boolean noteScan(ToneMap toneMap, int sequence) {
+ ", " + noteStatusElement.onTime);
}
} else {
LOG.finer(">>>Note scan PENDING low amp: " + sequence + ", " + note + ", " + time + ", "
+ amplitude + ", " + noteStatusElement.onTime + ", " + noteStatusElement.offTime + ", "
+ noteSustain + ", " + noteMaxDuration + ", " + noteOffThresholdhWithHysteresis);
LOG.finer(">>>Note scan PENDING low amp: " + sequence + ", " + note + ", " + time + ", " + amplitude
+ ", " + noteStatusElement.onTime + ", " + noteStatusElement.offTime + ", " + noteSustain
+ ", " + noteMaxDuration + ", " + noteOffThresholdhWithHysteresis);
LOG.finer(">>>Note scan PENDING - CONTINUE seq: " + sequence + ", note: " + note + ", sus: "
+ noteSustain + ", maxDur: " + noteMaxDuration + ", time " + time + ", offTime: "
+ noteStatusElement.offTime + ", onTime: " + noteStatusElement.onTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,9 +729,9 @@ private boolean playVoiceChannel1(MidiQueueMessage mqm) {
if (writeTrack) {
createEvent(voice1Track, voice1Channel, NOTEON, note, tick, volume);
}
LOG.finer(">>V1 MIDI NOTE ON: " + mqm.getSequence() + ", " + voice1Channel.num + ", "
+ note + ", " + volume + ", " + tick + ", " + amplitude + ", " + highVoiceThreshold
+ ", " + lowVoiceThreshold);
LOG.finer(">>V1 MIDI NOTE ON: " + mqm.getSequence() + ", " + voice1Channel.num + ", " + note
+ ", " + volume + ", " + tick + ", " + amplitude + ", " + highVoiceThreshold + ", "
+ lowVoiceThreshold);
} catch (InvalidMidiDataException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ public void buildToneMapFrame(ToneMap toneMap) {

float[] binStartingPointsInCents = getSource().getBinStartingPointsInCents();
float binWidth = getSource().getBinWidth();
int lowPitch = PitchSet.freqToMidiNote(PitchConverter.absoluteCentToHertz(binStartingPointsInCents[0]));
int highPitch = PitchSet.freqToMidiNote(
PitchConverter.absoluteCentToHertz(binStartingPointsInCents[binStartingPointsInCents.length - 1]));
int lowPitch = PitchSet
.freqToMidiNote(PitchConverter.absoluteCentToHertz(getSource().getHearingMinimumFrequencyInCents()));
int highPitch = PitchSet
.freqToMidiNote(PitchConverter.absoluteCentToHertz(getSource().getHearingMaximumFrequencyInCents()));

PitchSet pitchSet = new PitchSet(lowPitch, highPitch);

Expand Down Expand Up @@ -75,9 +76,13 @@ public void buildToneMapFrame(ToneMap toneMap) {
for (Map.Entry<Double, float[]> entry : features.entrySet()) {
float[] spectralEnergy = entry.getValue();
ToneMapElement[] elements = ttf.getElements();

for (int i = 0; i < spectralEnergy.length; i++) {
elements[i].amplitude += spectralEnergy[i];
elements[i].microTones.addMicroTone(entry.getKey(), spectralEnergy[i]);
int note = PitchSet
.freqToMidiNote(PitchConverter.absoluteCentToHertz(binStartingPointsInCents[i]));
int index = pitchSet.getIndex(note);
elements[index].amplitude += spectralEnergy[i];
elements[index].microTones.addMicroTone(entry.getKey(), spectralEnergy[i]);
}
}
ToneMapElement[] elements = ttf.getElements();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,23 @@ public class ConstantQSource extends AudioEventSource<float[]> {
private ParameterManager parameterManager;
float max = 0;

private int hearingMinimumFrequencyInCents;

private int hearingMaximumFrequencyInCents;

public ConstantQSource(AudioDispatcher dispatcher) {
super();
this.dispatcher = dispatcher;
this.sampleRate = dispatcher.getFormat().getSampleRate();
this.parameterManager = Instrument.getInstance().getController().getParameterManager();
this.windowSize = parameterManager.getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_CQ_WINDOW);
this.minimumFrequencyInCents = parameterManager
.getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_MINIMUM_FREQUENCY_CENTS);
.getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_CQ_MINIMUM_FREQUENCY_CENTS);
this.maximumFrequencyInCents = parameterManager
.getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_CQ_MAXIMUM_FREQUENCY_CENTS);
this.hearingMinimumFrequencyInCents = parameterManager
.getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_MINIMUM_FREQUENCY_CENTS);
this.hearingMaximumFrequencyInCents = parameterManager
.getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_MAXIMUM_FREQUENCY_CENTS);
}

Expand Down Expand Up @@ -106,6 +114,14 @@ public int getMinimumFrequencyInCents() {
return minimumFrequencyInCents;
}

public int getHearingMaximumFrequencyInCents() {
return hearingMaximumFrequencyInCents;
}

public int getHearingMinimumFrequencyInCents() {
return hearingMinimumFrequencyInCents;
}

public float getSampleRate() {
return sampleRate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public void accept(List<NuMessage> messages) throws Exception {
ChordListElement chord = timeFrame.getChord();
LOG.finer(">>AudioChromaPostProcessor get chord: " + tmIndex + ", time: " + timeFrame.getStartTime());
if (chord != null) {
LOG.finer(">>AudioChromaPostProcessor got chord: " + tmIndex + ", time: "
+ timeFrame.getStartTime() + " ," + chord);
LOG.finer(">>AudioChromaPostProcessor got chord: " + tmIndex + ", time: " + timeFrame.getStartTime()
+ " ," + chord);
postChromaToneMap.trackChord(chord);
}
console.getVisor().updateChromaPostView(postChromaToneMap, timeFrame);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public class InstrumentParameterNames {
public static final String PERCEPTION_HEARING_CQ_SWITCH_WHITEN_COMPENSATE = "perception.hearing.cq.whitenCompensateSwitch";
public static final String PERCEPTION_HEARING_CQ_WHITEN_FACTOR = "perception.hearing.cq.whitenFactor";
public static final String PERCEPTION_HEARING_CQ_WHITEN_THRESHOLD = "perception.hearing.cq.whitenThreshold";
public static final String PERCEPTION_HEARING_CQ_MINIMUM_FREQUENCY_CENTS = "perception.hearing.cq.minimumFrequencyInCents";
public static final String PERCEPTION_HEARING_CQ_MAXIMUM_FREQUENCY_CENTS = "perception.hearing.cq.maximumFrequencyInCents";

public static final String PERCEPTION_HEARING_SP_LOW_THRESHOLD = "perception.hearing.sp.lowThreshold";
public static final String PERCEPTION_HEARING_SP_SIGNAL_MINIMUM = "perception.hearing.sp.signalMinimum";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public class ParametersPanel extends JPanel {
private JComboBox cqWindowComboBox;
private JComboBox pdWindowComboBox;
private JComboBox spWindowComboBox;
private JTextField hearingMinFreqCentsInput;
private JTextField hearingMaxFreqCentsInput;
private JTextField cqMinFreqCentsInput;
private JTextField cqMaxFreqCentsInput;
private JComboBox pdLowWindowComboBox;
private JSlider hpsHarmonicWeightingSlider;
private JSlider hpsPercussionWeightingSlider;
Expand Down Expand Up @@ -349,6 +349,40 @@ public void actionPerformed(ActionEvent e) {
audioComboPanel.add(new JLabel("Spectral Peaks Window Size: "));
audioComboPanel.add(spWindowComboBox);

JLabel cqMinFreqCentsLabel = new JLabel("CQ Min Cents: ");
cqMinFreqCentsInput = new JTextField(4);
cqMinFreqCentsInput.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String newValue = cqMinFreqCentsInput.getText();
cqMinFreqCentsLabel.setText(String.format("CQ Min Cents (%s):", newValue));
parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_CQ_MINIMUM_FREQUENCY_CENTS,
newValue);

}
});
cqMinFreqCentsInput.setText(
parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_CQ_MINIMUM_FREQUENCY_CENTS));
audioComboPanel.add(cqMinFreqCentsLabel);
audioComboPanel.add(cqMinFreqCentsInput);

JLabel cqMaxFreqCentsLabel = new JLabel("CQ Max Cents: ");
cqMaxFreqCentsInput = new JTextField(4);
cqMaxFreqCentsInput.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String newValue = cqMaxFreqCentsInput.getText();
cqMaxFreqCentsLabel.setText(String.format("CQ Max Cents (%s):", newValue));
parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_CQ_MAXIMUM_FREQUENCY_CENTS,
newValue);

}
});
cqMaxFreqCentsInput.setText(
parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_CQ_MAXIMUM_FREQUENCY_CENTS));
audioComboPanel.add(cqMaxFreqCentsLabel);
audioComboPanel.add(cqMaxFreqCentsInput);

parameterPanel.add(audioComboPanel);

JPanel tunerSwitchPanel = new JPanel();
Expand Down Expand Up @@ -2034,40 +2068,6 @@ public void actionPerformed(ActionEvent e) {
cqParamsPanel.add(chromaChordifyThresholdLabel);
cqParamsPanel.add(chromaChordifyThresholdInput);

JLabel hearingMinFreqCentsLabel = new JLabel("Hearing Min Frequency cents: ");
hearingMinFreqCentsInput = new JTextField(4);
hearingMinFreqCentsInput.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String newValue = cqLowThresholdInput.getText();
hearingMinFreqCentsLabel.setText(String.format("Hearing Min Frequency cents (%s):", newValue));
parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_MINIMUM_FREQUENCY_CENTS,
newValue);

}
});
hearingMinFreqCentsInput.setText(
parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_MINIMUM_FREQUENCY_CENTS));
cqParamsPanel.add(hearingMinFreqCentsLabel);
cqParamsPanel.add(hearingMinFreqCentsInput);

JLabel hearingMaxFreqCentsLabel = new JLabel("Hearing Max Frequency cents: ");
hearingMaxFreqCentsInput = new JTextField(4);
hearingMaxFreqCentsInput.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String newValue = cqLowThresholdInput.getText();
hearingMinFreqCentsLabel.setText(String.format("Hearing Max Frequency cents (%s):", newValue));
parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_MAXIMUM_FREQUENCY_CENTS,
newValue);

}
});
hearingMaxFreqCentsInput.setText(
parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_MAXIMUM_FREQUENCY_CENTS));
cqParamsPanel.add(hearingMaxFreqCentsLabel);
cqParamsPanel.add(hearingMaxFreqCentsInput);

JLabel cqLowThresholdLabel = new JLabel("CQ Low Threshold: ");
cqLowThresholdInput = new JTextField(4);
cqLowThresholdInput.addActionListener(new ActionListener() {
Expand Down Expand Up @@ -2879,9 +2879,9 @@ public void updateParameters() {
parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_CQ_WINDOW)));
spWindowComboBox.setSelectedIndex(getFFTWindowIndex(
parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_SP_WINDOW)));
hearingMaxFreqCentsInput.setText(
cqMaxFreqCentsInput.setText(
parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_MAXIMUM_FREQUENCY_CENTS));
hearingMinFreqCentsInput.setText(
cqMinFreqCentsInput.setText(
parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_MINIMUM_FREQUENCY_CENTS));
hpsHarmonicWeightingSlider.setValue(
parameterManager.getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_HPS_HARMONIC_WEIGHTING));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Formatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -221,6 +222,12 @@ public class SwingDesktopVisor implements Visor, AudioFeatureFrameObserver {

private JCheckBox showSynthesisSwitchCB;

private JTextField hearingMinFreqCentsInput;

private JTextField hearingMaxFreqCentsInput;

private JCheckBox updateThresholdSwitchCB;

@Override
public void startUp() {
LOG.warning(">>Using SwingDesktopVisor");
Expand Down Expand Up @@ -767,7 +774,19 @@ public void itemStateChanged(ItemEvent e) {
.setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_LOG));
graphControlPanel.add(showLogSwitchCB);

JLabel toneMapViewLowThresholdLabel = new JLabel("View Low Threshold: ");
final JButton parametersButton = new JButton("Update");
parametersButton.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
updateViewThresholds();
toneMapViewHighThresholdInput.setText(
parameterManager.getParameter(InstrumentParameterNames.MONITOR_TONEMAP_VIEW_HIGH_THRESHOLD));
}
});
graphControlPanel.add(parametersButton);

JLabel toneMapViewLowThresholdLabel = new JLabel("Low Threshold: ");
toneMapViewLowThresholdInput = new JTextField(4);
toneMapViewLowThresholdInput.addActionListener(new ActionListener() {
@Override
Expand Down Expand Up @@ -797,7 +816,7 @@ public void keyPressed(KeyEvent e) {
graphControlPanel.add(toneMapViewLowThresholdLabel);
graphControlPanel.add(toneMapViewLowThresholdInput);

JLabel toneMapViewHighThresholdLabel = new JLabel("View High Threshold: ");
JLabel toneMapViewHighThresholdLabel = new JLabel("High Threshold: ");
toneMapViewHighThresholdInput = new JTextField(4);
toneMapViewHighThresholdInput.addActionListener(new ActionListener() {
@Override
Expand Down Expand Up @@ -832,6 +851,19 @@ public void keyPressed(KeyEvent e) {
return panel;
}

protected void updateViewThresholds() {
if (toneMapViews.containsKey(currentToneMapViewType)) {
double maxAmplitude = toneMapView.getMaxAmplitude();

Formatter formatter = new Formatter();
formatter.format("%.2f", maxAmplitude);
parameterManager.setParameter(InstrumentParameterNames.MONITOR_TONEMAP_VIEW_HIGH_THRESHOLD,
formatter.toString());
formatter.close();
}
refreshMapViews();
}

protected boolean parseIntegerTextField(JTextField textField, int min, int max, String parameterName) {
try {
int value = Integer.parseInt(textField.getText());
Expand Down Expand Up @@ -1120,6 +1152,40 @@ public void keyPressed(KeyEvent e) {
actionPanel.add(audioRangeLabel);
actionPanel.add(audioRangeInput);

JLabel hearingMinFreqCentsLabel = new JLabel("Min Cents: ");
hearingMinFreqCentsInput = new JTextField(4);
hearingMinFreqCentsInput.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String newValue = hearingMinFreqCentsInput.getText();
parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_MINIMUM_FREQUENCY_CENTS,
newValue);

}
});
hearingMinFreqCentsInput.setText(
parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_MINIMUM_FREQUENCY_CENTS));
actionPanel.add(hearingMinFreqCentsLabel);
actionPanel.add(hearingMinFreqCentsInput);

JLabel hearingMaxFreqCentsLabel = new JLabel("Max Cents: ");
hearingMaxFreqCentsInput = new JTextField(4);
hearingMaxFreqCentsInput.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String newValue = hearingMaxFreqCentsInput.getText();
parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_MAXIMUM_FREQUENCY_CENTS,
newValue);

}
});
hearingMaxFreqCentsInput.setText(
parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_MAXIMUM_FREQUENCY_CENTS));
actionPanel.add(hearingMaxFreqCentsLabel);
actionPanel.add(hearingMaxFreqCentsInput);

actionPanel.add(new JLabel(" "));

final JButton parametersButton = new JButton("Parameters");

parametersButton.addActionListener(new ActionListener() {
Expand Down Expand Up @@ -1173,8 +1239,7 @@ public void windowClosing(WindowEvent e) {
}
});

JLabel spacer2Label = new JLabel(" ");
actionPanel.add(spacer2Label);
actionPanel.add(new JLabel(" "));

actionPanel.add(parametersButton);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public class ToneMapView extends JComponent implements ComponentListener, ToneMa

private Color[] rainbow;

private double maxAmplitude = 0;

private ParameterManager parameterManager;

public ToneMapView() {
Expand All @@ -109,6 +111,7 @@ public void clear() {
.getDoubleParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_OFFSET);
this.timeAxisEnd = this.timeAxisStart
+ parameterManager.getDoubleParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_RANGE);
maxAmplitude = 0;
this.toneMap = null;
this.currentWidth = getWidth();
this.currentHeight = getHeight();
Expand All @@ -121,6 +124,10 @@ public void clear() {
repaint();
}

public double getMaxAmplitude() {
return maxAmplitude;
}

public ToneMap getToneMap() {
return toneMap;
}
Expand All @@ -132,6 +139,7 @@ public void updateAxis() {
+ parameterManager.getDoubleParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_RANGE);
this.minCents = parameterManager.getIntParameter(InstrumentParameterNames.MONITOR_VIEW_PITCH_AXIS_OFFSET);
this.maxCents = parameterManager.getIntParameter(InstrumentParameterNames.MONITOR_VIEW_PITCH_AXIS_RANGE);
maxAmplitude = 0;
if (toneMap != null) {
renderToneMap(toneMap);
} else {
Expand Down Expand Up @@ -170,6 +178,7 @@ public void componentResized(ComponentEvent e) {

public void renderToneMap(ToneMap toneMap) {
this.toneMap = toneMap;
maxAmplitude = 0;
double timeStart = timeAxisStart / 1000;
double timeEnd = timeAxisEnd / 1000;
this.currentWidth = getWidth();
Expand Down Expand Up @@ -250,6 +259,9 @@ private void renderToneMap(ToneTimeFrame ttf) {
int width = (int) Math.ceil((((timeEnd - timeStart + 1) / (timeAxisRange)) * (getWidth() - 1)));
int height = (int) ((100.0 / (maxCents - minCents)) * getHeight());
amplitude = toneMapElement.amplitude;
if (maxAmplitude < amplitude) {
maxAmplitude = amplitude;
}
int greyValue = 0;
if (amplitude > highViewThreshold) {
greyValue = 255;
Expand Down
Loading

0 comments on commit 0f23e8c

Please sign in to comment.