diff --git a/instrument-core/src/main/java/jomu/instrument/audio/MidiSynthesizer.java b/instrument-core/src/main/java/jomu/instrument/audio/MidiSynthesizer.java index e1a31be6..b1779c89 100644 --- a/instrument-core/src/main/java/jomu/instrument/audio/MidiSynthesizer.java +++ b/instrument-core/src/main/java/jomu/instrument/audio/MidiSynthesizer.java @@ -274,18 +274,22 @@ public boolean open() { .getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_USER_SYNTHESIZER_SWITCH); boolean useMidiDevice = parameterManager .getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_DEVICE_PLAY_SWITCH); + boolean midiDeviceChannelSwitch = parameterManager + .getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_DEVICE_CHANNEL_SWITCH); String midiDeviceName = parameterManager .getParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_DEVICE_NAME); try { MidiDevice.Info midiOut = null; Info[] midiDevs = MidiSystem.getMidiDeviceInfo(); + boolean externalMidi = false; for (Info midiDev : midiDevs) { LOG.severe(">>MidiSynth Devs: " + midiDev.getName()); if (useMidiDevice && midiDeviceName != null && !midiDeviceName.isEmpty() && midiDev.getName().toLowerCase().startsWith(midiDeviceName.toLowerCase()) && midiOut == null) { midiOut = midiDev; + externalMidi = true; midiDevice = MidiSystem.getMidiDevice(midiOut); LOG.severe(">>MidiSynth Dev: " + midiDev.getName()); } @@ -359,9 +363,10 @@ public boolean open() { for (int i = 0; i < channels.length; i++) { if (midiDevice instanceof Synthesizer) { channels[i] = new ChannelData(null, i); + } else if (midiDeviceChannelSwitch) { + channels[i] = new ChannelData(null, channelDeviceMap.getOrDefault(i, 0)); } else { - int channelNumber = channelDeviceMap.getOrDefault(i, 0); - channels[i] = new ChannelData(null, channelNumber); + channels[i] = new ChannelData(null, 0); } } } else { diff --git a/instrument-core/src/main/java/jomu/instrument/control/InstrumentParameterNames.java b/instrument-core/src/main/java/jomu/instrument/control/InstrumentParameterNames.java index dcb88aac..63021f68 100644 --- a/instrument-core/src/main/java/jomu/instrument/control/InstrumentParameterNames.java +++ b/instrument-core/src/main/java/jomu/instrument/control/InstrumentParameterNames.java @@ -388,6 +388,7 @@ public class InstrumentParameterNames { public static final String ACTUATION_VOICE_USER_SYNTHESIZER_SWITCH = "actuation.voice.useSynthesizer"; public static final String ACTUATION_VOICE_MIDI_DEVICE_NAME = "actuation.voice.midiDeviceName"; public static final String ACTUATION_VOICE_MIDI_DEVICE_PLAY_SWITCH = "actuation.voice.midiDevicePlaySwitch"; + public static final String ACTUATION_VOICE_MIDI_DEVICE_CHANNEL_SWITCH = "actuation.voice.midiDeviceChannelSwitch"; public static final String ACTUATION_VOICE_RESYNTH_PLAY = "actuation.voice.playResynth"; public static final String ACTUATION_VOICE_MIDI_SOUND_FONTS = "actuation.voice.midiSoundFonts"; public static final String ACTUATION_VOICE_MIDI_PLAY_START_OFFSET = "actuation.voice.playStartOffset"; diff --git a/instrument-core/src/main/resources/instrument.properties b/instrument-core/src/main/resources/instrument.properties index 0a317e00..d171df07 100644 --- a/instrument-core/src/main/resources/instrument.properties +++ b/instrument-core/src/main/resources/instrument.properties @@ -1,417 +1,418 @@ -#Fri May 19 08:22:38 BST 2023 -actuation.voice.delay=0 -actuation.voice.glissandoRange=200 -actuation.voice.highThreshold=1.0 -actuation.voice.logFactor=10000 -actuation.voice.loopSave=false -actuation.voice.lowThreshold=0.00001 -actuation.voice.midiDeviceName=loopmidi -actuation.voice.midiDevicePlaySwitch=false -actuation.voice.midiInstrumentBase1=34 -actuation.voice.midiInstrumentBeat1=75 -actuation.voice.midiInstrumentBeat2=54 -actuation.voice.midiInstrumentBeat3=81 -actuation.voice.midiInstrumentBeat4=35 -actuation.voice.midiInstrumentChord1=20 -actuation.voice.midiInstrumentChord2=20 -actuation.voice.midiInstrumentPad1=49 -actuation.voice.midiInstrumentPad2=62 -actuation.voice.midiInstrumentVoice1=17 -actuation.voice.midiInstrumentVoice2=17 -actuation.voice.midiInstrumentVoice3=17 -actuation.voice.midiInstrumentVoice4=17 -actuation.voice.midiPlayBaseSwitch=false -actuation.voice.midiPlayBeat1Switch=false -actuation.voice.midiPlayBeat2Switch=false -actuation.voice.midiPlayBeat3Switch=false -actuation.voice.midiPlayBeat4Switch=false -actuation.voice.midiPlayChord1Switch=false -actuation.voice.midiPlayChord2Switch=false -actuation.voice.midiPlayPadChordsSwitch=true -actuation.voice.midiPlayLogSwitch=true -actuation.voice.midiPlayPad1Switch=false -actuation.voice.midiPlayPad2Switch=false -actuation.voice.midiPlayVoice1Switch=true -actuation.voice.midiPlayVoice2Switch=true -actuation.voice.midiPlayVoice3Switch=true -actuation.voice.midiPlayVoice4Switch=true -actuation.voice.midiPlayVolumeSwitch=false -actuation.voice.audioPlaybackLoopSwitch=false -actuation.voice.midiSynthTracksSwitch=true -actuation.voice.midiVolumeBase1=100 -actuation.voice.midiVolumeBeat1=100 -actuation.voice.midiVolumeBeat2=100 -actuation.voice.midiVolumeBeat3=100 -actuation.voice.midiVolumeBeat4=100 -actuation.voice.midiVolumeChord1=100 -actuation.voice.midiVolumeChord2=100 -actuation.voice.midiVolumePad1=100 -actuation.voice.midiVolumePad2=100 -actuation.voice.midiVolumeVoice1=100 -actuation.voice.midiVolumeVoice2=100 -actuation.voice.midiVolumeVoice3=100 -actuation.voice.midiVolumeVoice4=100 -actuation.voice.audioVolumePlayback=100 -actuation.voice.pausePlaySwitch=false -actuation.voice.playAudio=false -actuation.voice.playMidi=false -actuation.voice.playPeaks=false -actuation.voice.playRepeat=0 -actuation.voice.playResynth=false -actuation.voice.playStartOffset=0 -actuation.voice.playEndOffset=1000 -actuation.voice.silentWrite=false -actuation.voice.trackWriteSwitch=false -actuation.voice.useSynthesizer=true -audio.tuner.bottomFormantFactor=1 -audio.tuner.bottomFormantHigh=0 -audio.tuner.bottomFormantLow=0 -audio.tuner.bottomFormantMid=0 -audio.tuner.bottomFormantRange=0 -audio.tuner.clearHeadNotesSwitch=false -audio.tuner.clearIsolatedNotesPitchRange=4 -audio.tuner.clearIsolatedNotesPowerFactor=0.9 -audio.tuner.clearIsolatedNotesSwitch=false -audio.tuner.clearIsolatedNotesTimeRange=400 -audio.tuner.clearNoteEdgeFactor=2 -audio.tuner.clearNotesOnCreateSwitch=false -audio.tuner.clearTailNotesSwitch=false -audio.tuner.clearVibratoNotesSwitch=false -audio.tuner.clearVibratoNotesTimeRange=1000 -audio.tuner.formantFactor=70 -audio.tuner.formantHigh=110 -audio.tuner.formantLow=70 -audio.tuner.formantMid=80 -audio.tuner.formantRange=20 -audio.tuner.harmonic1Setting=100 -audio.tuner.harmonic2Setting=100 -audio.tuner.harmonic3Setting=100 -audio.tuner.harmonic4Setting=100 -audio.tuner.harmonic5Setting=60 -audio.tuner.harmonic6Setting=50 -audio.tuner.harmonicAccumulateSwitch=false -audio.tuner.harmonicAttenuateSwitch=true -audio.tuner.harmonicDriftFactor=0.1 -audio.tuner.harmonicGuitarSwitch=false -audio.tuner.harmonicOperatorSwitch=false -audio.tuner.harmonicSweep=400 -audio.tuner.harmonicWeightingSwitch=false -audio.tuner.hysteresisWeight=1.0 -audio.tuner.n1Setting=4 -audio.tuner.n1Switch=false -audio.tuner.n2Setting=100 -audio.tuner.n2Switch=false -audio.tuner.n3Setting=100 -audio.tuner.n3Switch=false -audio.tuner.n4Setting=100 -audio.tuner.n4Switch=false -audio.tuner.n5Setting=100 -audio.tuner.n5Switch=false -audio.tuner.n6Setting=30 -audio.tuner.n6Switch=false -audio.tuner.n7Switch=true -audio.tuner.normalizePeak=0.1 -audio.tuner.normalizeSetting=100 -audio.tuner.normalizeThreshold=0.01 -audio.tuner.normalizeTrough=0.05 -audio.tuner.noteHigh=10 -audio.tuner.noteLow=5 -audio.tuner.noteMaxDuration=3000 -audio.tuner.noteMinDuration=5 -audio.tuner.notePeaksMaxDuration=3000 -audio.tuner.notePeaksMinDuration=10 -audio.tuner.noteScan.attenuateHarmonicsSwitch=true -audio.tuner.noteScan.attenuateSemitonesSwitch=true -audio.tuner.noteScan.attenuateUndertonesSwitch=true -audio.tuner.noteSpectralMaxDuration=3000 -audio.tuner.noteSpectralMinDuration=10 -audio.tuner.noteSustain=0 -audio.tuner.peakSwitch=false -audio.tuner.pitchHigh=72 -audio.tuner.pitchLow=36 -audio.tuner.timbre.cqSwitch=false -audio.tuner.timbre.frequencyRange=10 -audio.tuner.timbre.frequencyRatio=0.1 -audio.tuner.timbre.medianRange=100 -audio.tuner.timbre.medianRatio=0.01 -audio.tuner.timbre.vibratoRatio=0.01 -audio.tuner.timbre.notateSwitch=false -audio.tuner.topFormantFactor=1 -audio.tuner.topFormantHigh=0 -audio.tuner.topFormantLow=0 -audio.tuner.topFormantMid=0 -audio.tuner.topFormantRange=0 -control.parameter.style=default -monitor.tonemap.view.highThreshold=1.0 -monitor.tonemap.view.lowThreshold=0.001 -monitor.view.pitchAxisOffset=0 -monitor.view.pitchAxisRange=12000 -monitor.view.showColour=false -monitor.view.showLog=true -monitor.view.showPeaks=false -monitor.view.showStats=false -monitor.view.showSynthesis=false -monitor.view.showPower=false -monitor.view.showTracking=false -monitor.view.showNotes=true -monitor.view.showChords=false -monitor.view.showBase=false -monitor.view.showBeats=false -monitor.view.timeAxisOffset=0 -monitor.view.timeAxisRange=34000 -monitor.view.updateView=false -perception.hearing.ai.parameterDimensionsFile=parameter-dimensions.properties -perception.hearing.ai.parameterDimensionsSource=/instrumentai/VOICE_4NOTES_10secC3.wav -perception.hearing.ai.parameterDimensionsTarget=/instrumentai/4notes10secA3.mid -#perception.hearing.ai.parameterDimensionsSource=/instrumentai/PIANO_4CHORD_10secC3.mp3 -#perception.hearing.ai.parameterDimensionsTarget=/instrumentai/4chord10secC3.mid -#perception.hearing.ai.parameterDimensionsSource=/instrumentai/c3eg-epiano-3.mp3 -#perception.hearing.ai.parameterDimensionsTarget=/instrumentai/c2egchord-2-4sec.mid -#perception.hearing.ai.parameterStyleFile=ai-c3eg-2-ep-best -perception.hearing.ai.parameterStyleFile=ai-default -perception.hearing.ai.searchCombinations=true -perception.hearing.ai.searchCount=0 -perception.hearing.ai.searchOffset=0 -perception.hearing.ai.searchThreshold=-100 -perception.hearing.audioDefaultFile=3notescale.wav -perception.hearing.audioFeatureInterval=50 -perception.hearing.audioFrameStoreDirectory=audio/framestore -perception.hearing.audioGainCompressFactor=1 -perception.hearing.audioHighPass=0 -perception.hearing.audioLowPass=4000 -perception.hearing.audioOffset=0 -perception.hearing.audioPadBefore=0 -perception.hearing.audioPadAfter=3 -perception.hearing.audioProjectDirectory=audio/project -perception.hearing.audioRange=30000 -perception.hearing.audioRecordDirectory=audio/recording -perception.hearing.audioRecordSwitch=false -perception.hearing.audioResampleSwitch=false -perception.hearing.audioSmoothFactor=0 -perception.hearing.audioSourceDirectory=data -perception.hearing.audioTimeStretch=0 -perception.hearing.audioPitchShift=0 -perception.hearing.autocorrelation.correlationThreshold=0.2 -perception.hearing.autocorrelation.maxLag=1000 -perception.hearing.autocorrelation.sacfSwitch=true -perception.hearing.autocorrelation.undertoneRange=4 -perception.hearing.autocorrelation.undertoneRemoveSwitch=true -perception.hearing.autocorrelation.undertoneThreshold=10 -perception.hearing.beats.sensitivity=20 -perception.hearing.beats.threshold=8 -perception.hearing.calibrateForwardSwitch=true -perception.hearing.calibrateRange=5 -perception.hearing.calibrateSwitch=true -perception.hearing.chroma.ceilingSwitch=false -perception.hearing.chroma.chordifySharpenSwitch=true -perception.hearing.chroma.chordifySwitch=true -perception.hearing.chroma.chordifyThreshold=0.1 -perception.hearing.chroma.cqOriginSwitch=false -perception.hearing.chroma.downSampleFactor=10 -perception.hearing.chroma.harmonicsSwitch=false -perception.hearing.chroma.normaliseThreshold=0.001 -perception.hearing.chroma.rootNote=24 -perception.hearing.chroma.hpsSwitch=false -perception.hearing.chroma.smoothFactor=4 -perception.cortex.shortCircuitSwitch=false -perception.hearing.cq.adaptiveWhitenFactor=0.3 -perception.hearing.cq.adaptiveWhitenSwitch=false -perception.hearing.cq.adaptiveWhitenThreshold=0.0005 -perception.hearing.cq.binsPerOctave=36 -perception.hearing.cq.compression=1 -perception.hearing.cq.compressionLogSwitch=false -perception.hearing.cq.compressionMaxSwitch=false -perception.hearing.cq.compressionSwitch=false -perception.hearing.cq.decibelLevel=0.005 -perception.hearing.cq.decibelSwitch=false -perception.hearing.cq.envelopeWhitenAttackFactor=1 -perception.hearing.cq.envelopeWhitenDecayFactor=0.2 -perception.hearing.cq.envelopeWhitenPostSwitch=false -perception.hearing.cq.envelopeWhitenPreSwitch=false -perception.hearing.cq.envelopeWhitenThreshold=0.01 -perception.hearing.cq.lowThreshold=0.0001 -perception.hearing.cq.highThreshold=1.0 -perception.hearing.cq.lowThresholdSwitch=true -perception.hearing.cq.maximumFrequencyInCents=10800 -perception.hearing.cq.minimumFrequencyInCents=2400 -perception.hearing.cq.normaliseMaxSwitch=false -perception.hearing.cq.normaliseSwitch=false -perception.hearing.cq.normaliseThreshold=400.0 -perception.hearing.cq.postHarmonicsSwitch=false -perception.hearing.cq.postSharpenSwitch=true -perception.hearing.cq.preHarmonicsSwitch=false -perception.hearing.cq.preSharpenSwitch=true -perception.hearing.cq.scaleSwitch=false -perception.hearing.cq.sharpenHarmonicSwitch=false -perception.hearing.cq.sharpenThreshold=0.99 -perception.hearing.cq.signalMinimum=0 -perception.hearing.cq.squareSwitch=false -perception.hearing.cq.thresholdFactor=0.5 -perception.hearing.cq.whitenCompensateSwitch=false -perception.hearing.cq.whitenFactor=50 -perception.hearing.cq.whitenSwitch=false -perception.hearing.defaultSampleRate=44100 -perception.hearing.defaultWindow=1024 -perception.hearing.exportDeltaSwitch=true -perception.hearing.harmonicHighNote=108 -perception.hearing.harmonicLowNote=24 -perception.hearing.hps.cqOriginSwitch=false -perception.hearing.hps.harmonicMedian=6 -perception.hearing.hps.harmonicWeighting=80 -perception.hearing.hps.maskFactor=1 -perception.hearing.hps.medianSwitch=true -perception.hearing.hps.percussionMedian=20 -perception.hearing.hps.percussionWeighting=20 -perception.hearing.integration.cqSwitch=true -perception.hearing.integration.hpsSwitch=false -perception.hearing.integration.percussionSwitch=false -perception.hearing.integration.mfccSwitch=false -perception.hearing.integration.peaksSwitch=false -perception.hearing.integration.pitchSwitch=false -perception.hearing.integration.sacfSwitch=false -perception.hearing.integration.spSwitch=false -perception.hearing.integration.spectralSwitch=false -perception.hearing.integration.tpSwitch=false -perception.hearing.integration.yinSwitch=false -perception.hearing.integration.envelopeWhitenSwitch=false -perception.hearing.maximumFrequencyInCents=10800 -perception.hearing.microToneSwitch=true -perception.hearing.minPeakSize=5 -perception.hearing.minimumFrequencyInCents=2400 -perception.hearing.noiseFloorFactor=5.0 -perception.hearing.noiseFloorMedianFilterLenth=7 -perception.hearing.notate.applyFormantsSwitch=false -perception.hearing.notate.compression=30.0 -perception.hearing.notate.compressionSwitch=true -perception.hearing.notate.peakSwitch=true -perception.hearing.notate.sweepRange=50 -perception.hearing.notetracker.clearRangeLower=300 -perception.hearing.notetracker.clearRangeUpper=200 -perception.hearing.notetracker.discardTrackRange=100 -perception.hearing.notetracker.maxTracksLower=10 -perception.hearing.notetracker.maxTracksUpper=20 -perception.hearing.notetracker.overlapSalientNoteRange=4 -perception.hearing.notetracker.overlapSalientTimeRange=300 -perception.hearing.notetracker.salientNoteRange=12 -perception.hearing.notetracker.salientTimeNoteFactor=4 -perception.hearing.notetracker.salientTimeRange=1000 -perception.hearing.numberOfSpectralPeaks=1 -perception.hearing.onset.cqOriginSwitch=true -perception.hearing.onset.edgeFactor=80 -perception.hearing.onset.interval=0.03 -perception.hearing.onset.sensitivity=20 -perception.hearing.onset.silenceThreshold=-70.0 -perception.hearing.onset.smoothingFactor=90 -perception.hearing.onset.threshold=0.3 -perception.hearing.onset.peaksSweep=3 -perception.hearing.onset.peaksThreshold=0.4 -perception.hearing.onset.peaksEdgeFactor=0.1 -perception.hearing.onset.hpsSwitch=false -perception.hearing.peaksSwitch=true -perception.hearing.percussion.sensitivity=40 -perception.hearing.percussion.threshold=5 -perception.hearing.pidSwitch=false -perception.hearing.pidDFactor=-0.999 -perception.hearing.pidIFactor=0.3 -perception.hearing.pidPFactor=0.3 -perception.hearing.pitch.detect.compressionSwitch=false -perception.hearing.pitch.detect.compresssion=1 -perception.hearing.pitch.detect.harmonics=7 -perception.hearing.pitch.detect.klapuriSwitch=false -perception.hearing.pitch.detect.lowThreshold=1 -perception.hearing.pitch.detect.tarsosSwitch=true -perception.hearing.pitch.detect.whitenerSwitch=false -perception.hearing.powerSquaredSwitch=false -perception.hearing.sink.sweepRange=0 -perception.hearing.sp.compression=1 -perception.hearing.sp.compressionSwitch=false -perception.hearing.sp.decibelLevel=0.01 -perception.hearing.sp.decibelSwitch=true -perception.hearing.sp.lowThreshold=0.01 -perception.hearing.sp.lowThresholdSwitch=false -perception.hearing.sp.normaliseSwitch=false -perception.hearing.sp.normaliseThreshold=400.0 -perception.hearing.sp.signalMinimum=0.0000001 -perception.hearing.sp.squareSwitch=false -perception.hearing.sp.thresholdFactor=0.5 -perception.hearing.streamSaveSwitch=false -perception.hearing.streamSaveIndex=0 -perception.hearing.synthesis.aggregateChordsSwitch=true -perception.hearing.synthesis.baseMeasure=4 -perception.hearing.synthesis.baseOctave=2 -perception.hearing.synthesis.basePattern=1 -perception.hearing.synthesis.baseQuantizeSource=1 -perception.hearing.synthesis.baseSource=0 -perception.hearing.synthesis.baseTiming=0 -perception.hearing.synthesis.beatMetronomeCalibrate=false -perception.hearing.synthesis.beatMetronomeStart=0 -perception.hearing.synthesis.beatMetronomeDistance=1 -perception.hearing.synthesis.beatMetronomeLength=0.2 -perception.hearing.synthesis.beat1Source=6 -perception.hearing.synthesis.beat1Measure=4 -perception.hearing.synthesis.beat1Offset=0 -perception.hearing.synthesis.beat1Pattern=4 -perception.hearing.synthesis.beatTiming=0 -perception.hearing.synthesis.beat2Source=6 -perception.hearing.synthesis.beat2Measure=4 -perception.hearing.synthesis.beat2Offset=0 -perception.hearing.synthesis.beat2Pattern=4 -perception.hearing.synthesis.beat3Source=6 -perception.hearing.synthesis.beat3Measure=4 -perception.hearing.synthesis.beat3Offset=0 -perception.hearing.synthesis.beat3Pattern=4 -perception.hearing.synthesis.beat4Source=6 -perception.hearing.synthesis.beat4Measure=4 -perception.hearing.synthesis.beat4Offset=0 -perception.hearing.synthesis.beat4Pattern=4 -perception.hearing.synthesis.chordFirstSwitch=true -perception.hearing.synthesis.chordTiming=0 -perception.hearing.synthesis.chord1Measure=2 -perception.hearing.synthesis.chord1Offset=0 -perception.hearing.synthesis.chord1Octave=4 -perception.hearing.synthesis.chord1Pattern=1 -perception.hearing.synthesis.chord1QuantizeSource=2 -perception.hearing.synthesis.chord1Source=0 -perception.hearing.synthesis.chord1Invert=false -perception.hearing.synthesis.chord2Offset=0 -perception.hearing.synthesis.chord2Measure=2 -perception.hearing.synthesis.chord2Octave=4 -perception.hearing.synthesis.chord2Pattern=1 -perception.hearing.synthesis.chord2QuantizeSource=1 -perception.hearing.synthesis.chord2Source=0 -perception.hearing.synthesis.chord2Invert=false -perception.hearing.synthesis.chord3Measure=2 -perception.hearing.synthesis.chord3Offset=0 -perception.hearing.synthesis.chord3Octave=4 -perception.hearing.synthesis.chord3Pattern=0 -perception.hearing.synthesis.chord3QuantizeSource=1 -perception.hearing.synthesis.chord3Source=0 -perception.hearing.synthesis.chord3Invert=false -perception.hearing.synthesis.chord4Measure=2 -perception.hearing.synthesis.chord4Offset=0 -perception.hearing.synthesis.chord4Octave=4 -perception.hearing.synthesis.chord4Pattern=0 -perception.hearing.synthesis.chord4QuantizeSource=1 -perception.hearing.synthesis.chord4Source=0 -perception.hearing.synthesis.chord4Invert=false -perception.hearing.synthesis.cleanTracksSwitch=false -perception.hearing.synthesis.fillChordsSwitch=false -perception.hearing.synthesis.fillLegatoSwitch=false -perception.hearing.synthesis.fillNotesSwitch=false -perception.hearing.synthesis.minTimeIncrement=0.11 -perception.hearing.synthesis.pad1Octave=4 -perception.hearing.synthesis.pad2Octave=4 -perception.hearing.synthesis.quantizeBeat=2 -perception.hearing.synthesis.quantizePercent=100 -perception.hearing.synthesis.quantizeRange=1000 -perception.hearing.synthesis.quantizeSource=1 -perception.hearing.synthesis.sweepRange=30 -perception.hearing.synthesis.timeSignature=4 -perception.hearing.tonemap.maximumFrequency=4000 -perception.hearing.tonemap.minimumFrequency=27 -perception.hearing.tonemap.persistenceMode=2 -perception.hearing.tuner.signalMinimum=0.00001 -perception.hearing.tuner.thresholdFactor=0.6 -perception.hearing.tunerSwitch=false -perception.hearing.yin.lowPass=300 -storage.objectStore.basePath=data +#Fri May 19 08:22:38 BST 2023 +actuation.voice.delay=0 +actuation.voice.glissandoRange=200 +actuation.voice.highThreshold=1.0 +actuation.voice.logFactor=10000 +actuation.voice.loopSave=false +actuation.voice.lowThreshold=0.00001 +actuation.voice.midiDeviceName=loopmidi +actuation.voice.midiDevicePlaySwitch=false +actuation.voice.midiDeviceChannelSwitch=false +actuation.voice.midiInstrumentBase1=34 +actuation.voice.midiInstrumentBeat1=75 +actuation.voice.midiInstrumentBeat2=54 +actuation.voice.midiInstrumentBeat3=81 +actuation.voice.midiInstrumentBeat4=35 +actuation.voice.midiInstrumentChord1=20 +actuation.voice.midiInstrumentChord2=20 +actuation.voice.midiInstrumentPad1=49 +actuation.voice.midiInstrumentPad2=62 +actuation.voice.midiInstrumentVoice1=17 +actuation.voice.midiInstrumentVoice2=17 +actuation.voice.midiInstrumentVoice3=17 +actuation.voice.midiInstrumentVoice4=17 +actuation.voice.midiPlayBaseSwitch=false +actuation.voice.midiPlayBeat1Switch=false +actuation.voice.midiPlayBeat2Switch=false +actuation.voice.midiPlayBeat3Switch=false +actuation.voice.midiPlayBeat4Switch=false +actuation.voice.midiPlayChord1Switch=false +actuation.voice.midiPlayChord2Switch=false +actuation.voice.midiPlayPadChordsSwitch=true +actuation.voice.midiPlayLogSwitch=true +actuation.voice.midiPlayPad1Switch=false +actuation.voice.midiPlayPad2Switch=false +actuation.voice.midiPlayVoice1Switch=true +actuation.voice.midiPlayVoice2Switch=true +actuation.voice.midiPlayVoice3Switch=true +actuation.voice.midiPlayVoice4Switch=true +actuation.voice.midiPlayVolumeSwitch=false +actuation.voice.audioPlaybackLoopSwitch=false +actuation.voice.midiSynthTracksSwitch=true +actuation.voice.midiVolumeBase1=100 +actuation.voice.midiVolumeBeat1=100 +actuation.voice.midiVolumeBeat2=100 +actuation.voice.midiVolumeBeat3=100 +actuation.voice.midiVolumeBeat4=100 +actuation.voice.midiVolumeChord1=100 +actuation.voice.midiVolumeChord2=100 +actuation.voice.midiVolumePad1=100 +actuation.voice.midiVolumePad2=100 +actuation.voice.midiVolumeVoice1=100 +actuation.voice.midiVolumeVoice2=100 +actuation.voice.midiVolumeVoice3=100 +actuation.voice.midiVolumeVoice4=100 +actuation.voice.audioVolumePlayback=100 +actuation.voice.pausePlaySwitch=false +actuation.voice.playAudio=false +actuation.voice.playMidi=false +actuation.voice.playPeaks=false +actuation.voice.playRepeat=0 +actuation.voice.playResynth=false +actuation.voice.playStartOffset=0 +actuation.voice.playEndOffset=1000 +actuation.voice.silentWrite=false +actuation.voice.trackWriteSwitch=false +actuation.voice.useSynthesizer=true +audio.tuner.bottomFormantFactor=1 +audio.tuner.bottomFormantHigh=0 +audio.tuner.bottomFormantLow=0 +audio.tuner.bottomFormantMid=0 +audio.tuner.bottomFormantRange=0 +audio.tuner.clearHeadNotesSwitch=false +audio.tuner.clearIsolatedNotesPitchRange=4 +audio.tuner.clearIsolatedNotesPowerFactor=0.9 +audio.tuner.clearIsolatedNotesSwitch=false +audio.tuner.clearIsolatedNotesTimeRange=400 +audio.tuner.clearNoteEdgeFactor=2 +audio.tuner.clearNotesOnCreateSwitch=false +audio.tuner.clearTailNotesSwitch=false +audio.tuner.clearVibratoNotesSwitch=false +audio.tuner.clearVibratoNotesTimeRange=1000 +audio.tuner.formantFactor=70 +audio.tuner.formantHigh=110 +audio.tuner.formantLow=70 +audio.tuner.formantMid=80 +audio.tuner.formantRange=20 +audio.tuner.harmonic1Setting=100 +audio.tuner.harmonic2Setting=100 +audio.tuner.harmonic3Setting=100 +audio.tuner.harmonic4Setting=100 +audio.tuner.harmonic5Setting=60 +audio.tuner.harmonic6Setting=50 +audio.tuner.harmonicAccumulateSwitch=false +audio.tuner.harmonicAttenuateSwitch=true +audio.tuner.harmonicDriftFactor=0.1 +audio.tuner.harmonicGuitarSwitch=false +audio.tuner.harmonicOperatorSwitch=false +audio.tuner.harmonicSweep=400 +audio.tuner.harmonicWeightingSwitch=false +audio.tuner.hysteresisWeight=1.0 +audio.tuner.n1Setting=4 +audio.tuner.n1Switch=false +audio.tuner.n2Setting=100 +audio.tuner.n2Switch=false +audio.tuner.n3Setting=100 +audio.tuner.n3Switch=false +audio.tuner.n4Setting=100 +audio.tuner.n4Switch=false +audio.tuner.n5Setting=100 +audio.tuner.n5Switch=false +audio.tuner.n6Setting=30 +audio.tuner.n6Switch=false +audio.tuner.n7Switch=true +audio.tuner.normalizePeak=0.1 +audio.tuner.normalizeSetting=100 +audio.tuner.normalizeThreshold=0.01 +audio.tuner.normalizeTrough=0.05 +audio.tuner.noteHigh=10 +audio.tuner.noteLow=5 +audio.tuner.noteMaxDuration=3000 +audio.tuner.noteMinDuration=5 +audio.tuner.notePeaksMaxDuration=3000 +audio.tuner.notePeaksMinDuration=10 +audio.tuner.noteScan.attenuateHarmonicsSwitch=true +audio.tuner.noteScan.attenuateSemitonesSwitch=true +audio.tuner.noteScan.attenuateUndertonesSwitch=true +audio.tuner.noteSpectralMaxDuration=3000 +audio.tuner.noteSpectralMinDuration=10 +audio.tuner.noteSustain=0 +audio.tuner.peakSwitch=false +audio.tuner.pitchHigh=72 +audio.tuner.pitchLow=36 +audio.tuner.timbre.cqSwitch=false +audio.tuner.timbre.frequencyRange=10 +audio.tuner.timbre.frequencyRatio=0.1 +audio.tuner.timbre.medianRange=100 +audio.tuner.timbre.medianRatio=0.01 +audio.tuner.timbre.vibratoRatio=0.01 +audio.tuner.timbre.notateSwitch=false +audio.tuner.topFormantFactor=1 +audio.tuner.topFormantHigh=0 +audio.tuner.topFormantLow=0 +audio.tuner.topFormantMid=0 +audio.tuner.topFormantRange=0 +control.parameter.style=default +monitor.tonemap.view.highThreshold=1.0 +monitor.tonemap.view.lowThreshold=0.001 +monitor.view.pitchAxisOffset=0 +monitor.view.pitchAxisRange=12000 +monitor.view.showColour=false +monitor.view.showLog=true +monitor.view.showPeaks=false +monitor.view.showStats=false +monitor.view.showSynthesis=false +monitor.view.showPower=false +monitor.view.showTracking=false +monitor.view.showNotes=true +monitor.view.showChords=false +monitor.view.showBase=false +monitor.view.showBeats=false +monitor.view.timeAxisOffset=0 +monitor.view.timeAxisRange=34000 +monitor.view.updateView=false +perception.hearing.ai.parameterDimensionsFile=parameter-dimensions.properties +perception.hearing.ai.parameterDimensionsSource=/instrumentai/VOICE_4NOTES_10secC3.wav +perception.hearing.ai.parameterDimensionsTarget=/instrumentai/4notes10secA3.mid +#perception.hearing.ai.parameterDimensionsSource=/instrumentai/PIANO_4CHORD_10secC3.mp3 +#perception.hearing.ai.parameterDimensionsTarget=/instrumentai/4chord10secC3.mid +#perception.hearing.ai.parameterDimensionsSource=/instrumentai/c3eg-epiano-3.mp3 +#perception.hearing.ai.parameterDimensionsTarget=/instrumentai/c2egchord-2-4sec.mid +#perception.hearing.ai.parameterStyleFile=ai-c3eg-2-ep-best +perception.hearing.ai.parameterStyleFile=ai-default +perception.hearing.ai.searchCombinations=true +perception.hearing.ai.searchCount=0 +perception.hearing.ai.searchOffset=0 +perception.hearing.ai.searchThreshold=-100 +perception.hearing.audioDefaultFile=3notescale.wav +perception.hearing.audioFeatureInterval=50 +perception.hearing.audioFrameStoreDirectory=audio/framestore +perception.hearing.audioGainCompressFactor=1 +perception.hearing.audioHighPass=0 +perception.hearing.audioLowPass=4000 +perception.hearing.audioOffset=0 +perception.hearing.audioPadBefore=0 +perception.hearing.audioPadAfter=3 +perception.hearing.audioProjectDirectory=audio/project +perception.hearing.audioRange=30000 +perception.hearing.audioRecordDirectory=audio/recording +perception.hearing.audioRecordSwitch=false +perception.hearing.audioResampleSwitch=false +perception.hearing.audioSmoothFactor=0 +perception.hearing.audioSourceDirectory=data +perception.hearing.audioTimeStretch=0 +perception.hearing.audioPitchShift=0 +perception.hearing.autocorrelation.correlationThreshold=0.2 +perception.hearing.autocorrelation.maxLag=1000 +perception.hearing.autocorrelation.sacfSwitch=true +perception.hearing.autocorrelation.undertoneRange=4 +perception.hearing.autocorrelation.undertoneRemoveSwitch=true +perception.hearing.autocorrelation.undertoneThreshold=10 +perception.hearing.beats.sensitivity=20 +perception.hearing.beats.threshold=8 +perception.hearing.calibrateForwardSwitch=true +perception.hearing.calibrateRange=5 +perception.hearing.calibrateSwitch=true +perception.hearing.chroma.ceilingSwitch=false +perception.hearing.chroma.chordifySharpenSwitch=true +perception.hearing.chroma.chordifySwitch=true +perception.hearing.chroma.chordifyThreshold=0.1 +perception.hearing.chroma.cqOriginSwitch=false +perception.hearing.chroma.downSampleFactor=10 +perception.hearing.chroma.harmonicsSwitch=false +perception.hearing.chroma.normaliseThreshold=0.001 +perception.hearing.chroma.rootNote=24 +perception.hearing.chroma.hpsSwitch=false +perception.hearing.chroma.smoothFactor=4 +perception.cortex.shortCircuitSwitch=false +perception.hearing.cq.adaptiveWhitenFactor=0.3 +perception.hearing.cq.adaptiveWhitenSwitch=false +perception.hearing.cq.adaptiveWhitenThreshold=0.0005 +perception.hearing.cq.binsPerOctave=36 +perception.hearing.cq.compression=1 +perception.hearing.cq.compressionLogSwitch=false +perception.hearing.cq.compressionMaxSwitch=false +perception.hearing.cq.compressionSwitch=false +perception.hearing.cq.decibelLevel=0.005 +perception.hearing.cq.decibelSwitch=false +perception.hearing.cq.envelopeWhitenAttackFactor=1 +perception.hearing.cq.envelopeWhitenDecayFactor=0.2 +perception.hearing.cq.envelopeWhitenPostSwitch=false +perception.hearing.cq.envelopeWhitenPreSwitch=false +perception.hearing.cq.envelopeWhitenThreshold=0.01 +perception.hearing.cq.lowThreshold=0.0001 +perception.hearing.cq.highThreshold=1.0 +perception.hearing.cq.lowThresholdSwitch=true +perception.hearing.cq.maximumFrequencyInCents=10800 +perception.hearing.cq.minimumFrequencyInCents=2400 +perception.hearing.cq.normaliseMaxSwitch=false +perception.hearing.cq.normaliseSwitch=false +perception.hearing.cq.normaliseThreshold=400.0 +perception.hearing.cq.postHarmonicsSwitch=false +perception.hearing.cq.postSharpenSwitch=true +perception.hearing.cq.preHarmonicsSwitch=false +perception.hearing.cq.preSharpenSwitch=true +perception.hearing.cq.scaleSwitch=false +perception.hearing.cq.sharpenHarmonicSwitch=false +perception.hearing.cq.sharpenThreshold=0.99 +perception.hearing.cq.signalMinimum=0 +perception.hearing.cq.squareSwitch=false +perception.hearing.cq.thresholdFactor=0.5 +perception.hearing.cq.whitenCompensateSwitch=false +perception.hearing.cq.whitenFactor=50 +perception.hearing.cq.whitenSwitch=false +perception.hearing.defaultSampleRate=44100 +perception.hearing.defaultWindow=1024 +perception.hearing.exportDeltaSwitch=true +perception.hearing.harmonicHighNote=108 +perception.hearing.harmonicLowNote=24 +perception.hearing.hps.cqOriginSwitch=false +perception.hearing.hps.harmonicMedian=6 +perception.hearing.hps.harmonicWeighting=80 +perception.hearing.hps.maskFactor=1 +perception.hearing.hps.medianSwitch=true +perception.hearing.hps.percussionMedian=20 +perception.hearing.hps.percussionWeighting=20 +perception.hearing.integration.cqSwitch=true +perception.hearing.integration.hpsSwitch=false +perception.hearing.integration.percussionSwitch=false +perception.hearing.integration.mfccSwitch=false +perception.hearing.integration.peaksSwitch=false +perception.hearing.integration.pitchSwitch=false +perception.hearing.integration.sacfSwitch=false +perception.hearing.integration.spSwitch=false +perception.hearing.integration.spectralSwitch=false +perception.hearing.integration.tpSwitch=false +perception.hearing.integration.yinSwitch=false +perception.hearing.integration.envelopeWhitenSwitch=false +perception.hearing.maximumFrequencyInCents=10800 +perception.hearing.microToneSwitch=true +perception.hearing.minPeakSize=5 +perception.hearing.minimumFrequencyInCents=2400 +perception.hearing.noiseFloorFactor=5.0 +perception.hearing.noiseFloorMedianFilterLenth=7 +perception.hearing.notate.applyFormantsSwitch=false +perception.hearing.notate.compression=30.0 +perception.hearing.notate.compressionSwitch=true +perception.hearing.notate.peakSwitch=true +perception.hearing.notate.sweepRange=50 +perception.hearing.notetracker.clearRangeLower=300 +perception.hearing.notetracker.clearRangeUpper=200 +perception.hearing.notetracker.discardTrackRange=100 +perception.hearing.notetracker.maxTracksLower=10 +perception.hearing.notetracker.maxTracksUpper=20 +perception.hearing.notetracker.overlapSalientNoteRange=4 +perception.hearing.notetracker.overlapSalientTimeRange=300 +perception.hearing.notetracker.salientNoteRange=12 +perception.hearing.notetracker.salientTimeNoteFactor=4 +perception.hearing.notetracker.salientTimeRange=1000 +perception.hearing.numberOfSpectralPeaks=1 +perception.hearing.onset.cqOriginSwitch=true +perception.hearing.onset.edgeFactor=80 +perception.hearing.onset.interval=0.03 +perception.hearing.onset.sensitivity=20 +perception.hearing.onset.silenceThreshold=-70.0 +perception.hearing.onset.smoothingFactor=90 +perception.hearing.onset.threshold=0.3 +perception.hearing.onset.peaksSweep=3 +perception.hearing.onset.peaksThreshold=0.4 +perception.hearing.onset.peaksEdgeFactor=0.1 +perception.hearing.onset.hpsSwitch=false +perception.hearing.peaksSwitch=true +perception.hearing.percussion.sensitivity=40 +perception.hearing.percussion.threshold=5 +perception.hearing.pidSwitch=false +perception.hearing.pidDFactor=-0.999 +perception.hearing.pidIFactor=0.3 +perception.hearing.pidPFactor=0.3 +perception.hearing.pitch.detect.compressionSwitch=false +perception.hearing.pitch.detect.compresssion=1 +perception.hearing.pitch.detect.harmonics=7 +perception.hearing.pitch.detect.klapuriSwitch=false +perception.hearing.pitch.detect.lowThreshold=1 +perception.hearing.pitch.detect.tarsosSwitch=true +perception.hearing.pitch.detect.whitenerSwitch=false +perception.hearing.powerSquaredSwitch=false +perception.hearing.sink.sweepRange=0 +perception.hearing.sp.compression=1 +perception.hearing.sp.compressionSwitch=false +perception.hearing.sp.decibelLevel=0.01 +perception.hearing.sp.decibelSwitch=true +perception.hearing.sp.lowThreshold=0.01 +perception.hearing.sp.lowThresholdSwitch=false +perception.hearing.sp.normaliseSwitch=false +perception.hearing.sp.normaliseThreshold=400.0 +perception.hearing.sp.signalMinimum=0.0000001 +perception.hearing.sp.squareSwitch=false +perception.hearing.sp.thresholdFactor=0.5 +perception.hearing.streamSaveSwitch=false +perception.hearing.streamSaveIndex=0 +perception.hearing.synthesis.aggregateChordsSwitch=true +perception.hearing.synthesis.baseMeasure=4 +perception.hearing.synthesis.baseOctave=2 +perception.hearing.synthesis.basePattern=1 +perception.hearing.synthesis.baseQuantizeSource=1 +perception.hearing.synthesis.baseSource=0 +perception.hearing.synthesis.baseTiming=0 +perception.hearing.synthesis.beatMetronomeCalibrate=false +perception.hearing.synthesis.beatMetronomeStart=0 +perception.hearing.synthesis.beatMetronomeDistance=1 +perception.hearing.synthesis.beatMetronomeLength=0.2 +perception.hearing.synthesis.beat1Source=6 +perception.hearing.synthesis.beat1Measure=4 +perception.hearing.synthesis.beat1Offset=0 +perception.hearing.synthesis.beat1Pattern=4 +perception.hearing.synthesis.beatTiming=0 +perception.hearing.synthesis.beat2Source=6 +perception.hearing.synthesis.beat2Measure=4 +perception.hearing.synthesis.beat2Offset=0 +perception.hearing.synthesis.beat2Pattern=4 +perception.hearing.synthesis.beat3Source=6 +perception.hearing.synthesis.beat3Measure=4 +perception.hearing.synthesis.beat3Offset=0 +perception.hearing.synthesis.beat3Pattern=4 +perception.hearing.synthesis.beat4Source=6 +perception.hearing.synthesis.beat4Measure=4 +perception.hearing.synthesis.beat4Offset=0 +perception.hearing.synthesis.beat4Pattern=4 +perception.hearing.synthesis.chordFirstSwitch=true +perception.hearing.synthesis.chordTiming=0 +perception.hearing.synthesis.chord1Measure=2 +perception.hearing.synthesis.chord1Offset=0 +perception.hearing.synthesis.chord1Octave=4 +perception.hearing.synthesis.chord1Pattern=1 +perception.hearing.synthesis.chord1QuantizeSource=2 +perception.hearing.synthesis.chord1Source=0 +perception.hearing.synthesis.chord1Invert=false +perception.hearing.synthesis.chord2Offset=0 +perception.hearing.synthesis.chord2Measure=2 +perception.hearing.synthesis.chord2Octave=4 +perception.hearing.synthesis.chord2Pattern=1 +perception.hearing.synthesis.chord2QuantizeSource=1 +perception.hearing.synthesis.chord2Source=0 +perception.hearing.synthesis.chord2Invert=false +perception.hearing.synthesis.chord3Measure=2 +perception.hearing.synthesis.chord3Offset=0 +perception.hearing.synthesis.chord3Octave=4 +perception.hearing.synthesis.chord3Pattern=0 +perception.hearing.synthesis.chord3QuantizeSource=1 +perception.hearing.synthesis.chord3Source=0 +perception.hearing.synthesis.chord3Invert=false +perception.hearing.synthesis.chord4Measure=2 +perception.hearing.synthesis.chord4Offset=0 +perception.hearing.synthesis.chord4Octave=4 +perception.hearing.synthesis.chord4Pattern=0 +perception.hearing.synthesis.chord4QuantizeSource=1 +perception.hearing.synthesis.chord4Source=0 +perception.hearing.synthesis.chord4Invert=false +perception.hearing.synthesis.cleanTracksSwitch=false +perception.hearing.synthesis.fillChordsSwitch=false +perception.hearing.synthesis.fillLegatoSwitch=false +perception.hearing.synthesis.fillNotesSwitch=false +perception.hearing.synthesis.minTimeIncrement=0.11 +perception.hearing.synthesis.pad1Octave=4 +perception.hearing.synthesis.pad2Octave=4 +perception.hearing.synthesis.quantizeBeat=2 +perception.hearing.synthesis.quantizePercent=100 +perception.hearing.synthesis.quantizeRange=1000 +perception.hearing.synthesis.quantizeSource=1 +perception.hearing.synthesis.sweepRange=30 +perception.hearing.synthesis.timeSignature=4 +perception.hearing.tonemap.maximumFrequency=4000 +perception.hearing.tonemap.minimumFrequency=27 +perception.hearing.tonemap.persistenceMode=2 +perception.hearing.tuner.signalMinimum=0.00001 +perception.hearing.tuner.thresholdFactor=0.6 +perception.hearing.tunerSwitch=false +perception.hearing.yin.lowPass=300 +storage.objectStore.basePath=data diff --git a/instrument-desktop/src/main/java/jomu/instrument/desktop/monitor/swing/SwingDesktopVisor.java b/instrument-desktop/src/main/java/jomu/instrument/desktop/monitor/swing/SwingDesktopVisor.java index 29caa062..bce4eaf2 100644 --- a/instrument-desktop/src/main/java/jomu/instrument/desktop/monitor/swing/SwingDesktopVisor.java +++ b/instrument-desktop/src/main/java/jomu/instrument/desktop/monitor/swing/SwingDesktopVisor.java @@ -1,2972 +1,2994 @@ -package jomu.instrument.desktop.monitor.swing; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.Container; -import java.awt.Cursor; -import java.awt.DefaultKeyboardFocusManager; -import java.awt.Dimension; -import java.awt.EventQueue; -import java.awt.FlowLayout; -import java.awt.Frame; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.GraphicsEnvironment; -import java.awt.GridLayout; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.Toolkit; -import java.awt.Window; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.PrintStream; -import java.nio.file.Paths; -import java.time.LocalDateTime; -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; -import java.util.Map.Entry; -import java.util.TreeMap; -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.sound.sampled.LineUnavailableException; -import javax.swing.AbstractButton; -import javax.swing.BorderFactory; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JDialog; -import javax.swing.JFileChooser; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JSplitPane; -import javax.swing.JTabbedPane; -import javax.swing.JTextArea; -import javax.swing.JTextField; -import javax.swing.SwingConstants; -import javax.swing.SwingUtilities; -import javax.swing.WindowConstants; -import javax.swing.border.BevelBorder; -import javax.swing.border.CompoundBorder; -import javax.swing.border.EmptyBorder; -import javax.swing.border.EtchedBorder; - -import com.formdev.flatlaf.FlatLaf; -import com.formdev.flatlaf.intellijthemes.FlatMaterialDesignDarkIJTheme; - -import be.tarsos.dsp.ui.Axis; -import be.tarsos.dsp.ui.AxisUnit; -import be.tarsos.dsp.ui.CoordinateSystem; -import be.tarsos.dsp.ui.LinkedPanel; -import be.tarsos.dsp.ui.ViewPort; -import be.tarsos.dsp.ui.ViewPort.ViewPortChangedListener; -import be.tarsos.dsp.ui.layers.AmplitudeAxisLayer; -import be.tarsos.dsp.ui.layers.BackgroundLayer; -import be.tarsos.dsp.ui.layers.DragMouseListenerLayer; -import be.tarsos.dsp.ui.layers.HorizontalFrequencyAxisLayer; -import be.tarsos.dsp.ui.layers.Layer; -import be.tarsos.dsp.ui.layers.LegendLayer; -import be.tarsos.dsp.ui.layers.SelectionLayer; -import be.tarsos.dsp.ui.layers.TimeAxisLayer; -import be.tarsos.dsp.ui.layers.VerticalFrequencyAxisLayer; -import be.tarsos.dsp.ui.layers.ZoomMouseListenerLayer; -import be.tarsos.dsp.util.PitchConverter; -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.enterprise.inject.Alternative; -import jakarta.inject.Inject; -import jomu.instrument.Instrument; -import jomu.instrument.InstrumentException; -import jomu.instrument.audio.features.AudioFeatureFrame; -import jomu.instrument.audio.features.AudioFeatureFrameObserver; -import jomu.instrument.audio.features.ConstantQSource; -import jomu.instrument.audio.features.PitchDetectorSource; -import jomu.instrument.audio.features.SpectralInfo; -import jomu.instrument.audio.features.SpectralPeaksSource; -import jomu.instrument.audio.features.SpectrogramInfo; -import jomu.instrument.cognition.cell.Cell; -import jomu.instrument.control.Controller; -import jomu.instrument.control.Coordinator; -import jomu.instrument.control.InstrumentParameterNames; -import jomu.instrument.control.ParameterManager; -import jomu.instrument.monitor.Console; -import jomu.instrument.monitor.Visor; -import jomu.instrument.store.InstrumentStoreService; -import jomu.instrument.store.Storage; -import jomu.instrument.workspace.Workspace; -import jomu.instrument.workspace.tonemap.ToneMap; -import jomu.instrument.workspace.tonemap.ToneMapElement; -import jomu.instrument.workspace.tonemap.ToneTimeFrame; - -@ApplicationScoped -@Alternative -@jakarta.annotation.Priority(1) -public class SwingDesktopVisor implements Visor, AudioFeatureFrameObserver { - - private static final Logger LOG = Logger.getLogger(SwingDesktopVisor.class.getName()); - - @Inject - Instrument instrument; - - @Inject - ParameterManager parameterManager; - - @Inject - Storage storage; - - @Inject - InstrumentStoreService iss; - - @Inject - Workspace workspace; - - @Inject - Console console; - - @Inject - Controller controller; - - @Inject - Coordinator coordinator; - - LinkedPanel constantQPanel; - - CQLayer cqLayer; - - LinkedPanel cqPanel; - - SpectrumLayer noiseFloorLayer; - - PitchDetectLayer pdLayer; - LinkedPanel pitchDetectPanel; - SpectrumLayer spectrumLayer; - LinkedPanel spectrumPanel; - ToneMapView toneMapView; - String currentToneMapViewType; - - Map toneMapViews = new HashMap<>(); - - static final Integer[] fftWindowSizes = { 256, 512, 1024, 2048, 4096, 8192 }; - static final Integer[] inputSampleRate = { 8000, 11025, 22050, 44100, 48000, 96000, 192000 }; - - static final String[] toneMapViewTypesMode3 = new String[] { Cell.CellTypes.AUDIO_CQ.name(), - Cell.CellTypes.AUDIO_SYNTHESIS.name(), Cell.CellTypes.AUDIO_CQ_ORIGIN.name(), - Cell.CellTypes.AUDIO_CQ_MICRO_TONE.name(), Cell.CellTypes.AUDIO_TUNER_PEAKS.name(), - Cell.CellTypes.AUDIO_SPECTRAL_PEAKS.name(), Cell.CellTypes.AUDIO_PITCH.name(), - Cell.CellTypes.AUDIO_PHASE.name(), Cell.CellTypes.AUDIO_YIN.name(), Cell.CellTypes.AUDIO_SACF.name(), - Cell.CellTypes.AUDIO_MFCC.name(), Cell.CellTypes.AUDIO_CEPSTRUM.name(), Cell.CellTypes.AUDIO_NOTATE.name(), - Cell.CellTypes.AUDIO_NOTATE.name() + "_PEAKS", Cell.CellTypes.AUDIO_NOTATE.name() + "_SPECTRAL", - Cell.CellTypes.AUDIO_INTEGRATE.name(), Cell.CellTypes.AUDIO_INTEGRATE.name() + "_PEAKS", - Cell.CellTypes.AUDIO_INTEGRATE.name() + "_SPECTRAL", Cell.CellTypes.AUDIO_ONSET.name(), - Cell.CellTypes.AUDIO_PERCUSSION.name(), Cell.CellTypes.AUDIO_ONSET.name() + "_SMOOTHED", - Cell.CellTypes.AUDIO_HPS.name(), Cell.CellTypes.AUDIO_HPS.name() + "_HARMONIC_MASK", - Cell.CellTypes.AUDIO_HPS.name() + "_PERCUSSION_MASK", Cell.CellTypes.AUDIO_HPS.name() + "_HARMONIC", - Cell.CellTypes.AUDIO_HPS.name() + "_PERCUSSION", Cell.CellTypes.AUDIO_PRE_CHROMA.name(), - Cell.CellTypes.AUDIO_POST_CHROMA.name(), Cell.CellTypes.AUDIO_BEAT.name() }; - - static final String[] toneMapViewTypesMode2 = new String[] { Cell.CellTypes.AUDIO_CQ.name(), - Cell.CellTypes.AUDIO_SYNTHESIS.name(), Cell.CellTypes.AUDIO_INTEGRATE.name(), - Cell.CellTypes.AUDIO_NOTATE.name() }; - - File inputFile; - - JPanel diagnosticsPanel; - - ChromaView chromaView; - - BeatsView beatsView; - - JFrame mainframe; - - JPanel beatsPanel; - - JTextField audioFeatureIntervalInput; - JTextField timeAxisOffsetInput; - JTextField pitchAxisOffsetInput; - JTextField timeAxisRangeInput; - JTextField pitchAxisRangeInput; - JComboBox toneMapViewComboBox; - JCheckBox playMidiSwitchCB; - JCheckBox playAudioSwitchCB; - JTextField voicePlayerLowThresholdInput; - JTextField voicePlayerHighThresholdInput; - JTextField voicePlayerDelayInput; - JTextField frameNumberInput; - JTextField toneMapViewLowThresholdInput; - JTextField toneMapViewHighThresholdInput; - JTextField audioOffsetInput; - JTextField audioRangeInput; - JCheckBox recordSwitchCB; - JCheckBox playResynthSwitchCB; - TimeFramePanel timeFramePanel; - JButton chooseFileButton; - JButton startFileProcessingButton; - JButton startListeningButton; - JButton stopListeningButton; - JButton playAudioButton; - JButton playStreamButton; - JCheckBox playPeaksSwitchCB; - AbstractButton showPeaksSwitchCB; - JCheckBox showPowerSwitchCB; - JCheckBox showLogSwitchCB; - JCheckBox trackWriteSwitchCB; - JPanel visorPanel; - JFrame mainFrame; - Container upperPane; - JPanel contentPane; - JLabel statusLabel; - JLabel fileNameLabel; - JTextField hearingMinFreqCentsInput; - JTextField hearingMaxFreqCentsInput; - JCheckBox updateThresholdSwitchCB; - JCheckBox showColourSwitchCB; - JCheckBox silentWriteSwitchCB; - JCheckBox pausePlaySwitchCB; - JCheckBox midiSynthTracksSwitchCB; - JCheckBox showStatsSwitchCB; - JCheckBox midiPlayLogSwitchCB; - JTextField voicePlayerLogFactorInput; - JTextField voicePlayerGlissandoRangeInput; - - JTextField audioTimeStretchInput; - JTextField audioGainInput; - JTextField persistenceModeInput; - JTextField voicePlayerRepeatInput; - JCheckBox loopSaveSwitchCB; - JCheckBox midiPlayVolumeSwitchCB; - JCheckBox showNotesSwitchCB; - JCheckBox showChordsSwitchCB; - JCheckBox showBeatsSwitchCB; - JButton resetSystemButton; - JButton parametersButton; - JButton synthButton; - JButton updateViewButton; - JSplitPane toneMapViewTopPane; - JSplitPane toneMapViewBottomPane; - JComboBox fftWindowSizeComboBox; - JComboBox inputSampleRateCombobox; - - private JCheckBox showBaseSwitchCB; - - private JCheckBox resampleSwitchCB; - - private JTextField padBeforeInput; - - private JTextField padAfterInput; - - private JTextField audioPitchShiftInput; - - private JDialog parameterDialog; - - private boolean parameterDialogOpen; - - private ParametersPanel parameterPanel; - - private JDialog synthDialog; - - private boolean synthDialogOpen; - - protected SynthPanel synthPanel; - - private JCheckBox playMidiDeviceSwitchCB; - - private JCheckBox streamSaveSwitchCB; - - private JTextField streamIndexInput; - - private JTextField playStartOffsetInput; - - private JTextField playEndOffsetInput; - - private JTextField searchCountInput; - - private JCheckBox cortexShortCircuitSwitchCB; - - @Override - public void startUp() { - LOG.severe(">>Using SwingDesktopVisor"); - EventQueue.invokeLater(() -> { - buildMainFrame(); - }); - } - - @Override - public void shutdown() { - EventQueue.invokeLater(() -> { - closeMainFrame(); - }); - } - - public void updateStatusMessage(String message) { - statusLabel.setText(message); - } - - protected void buildMainFrame() { - FlatMaterialDesignDarkIJTheme.setup(); - FlatLaf.setUseNativeWindowDecorations(true); - mainFrame = new JFrame(); - mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); - mainFrame.setTitle("The Instrument"); - - buildContent(); - - initialise(mainFrame); - - upperPane.add(getContentPanel(), BorderLayout.CENTER); - - final int inset = 10; - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - mainFrame.setBounds(inset, inset, screenSize.width - inset * 2, screenSize.height - inset * 2); - mainFrame.pack(); - mainFrame.setVisible(true); - mainFrame.setExtendedState(mainFrame.getExtendedState() | Frame.MAXIMIZED_BOTH); - } - - protected void closeMainFrame() { - mainFrame.setVisible(false); - mainframe.dispose(); - } - - private void showStackTraceDialog(Throwable throwable, String title, String message) { - Window window = DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); - showStackTraceDialog(throwable, window, title, message); - } - - private void showEmailStatusInfoDialog(String title, String message) { - Window window = DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); - showEmailStatusInfoDialog(window, title, message); - } - - private void showStatusInfoDialog(String title, String message) { - Window window = DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); - showStatusInfoDialog(window, title, message); - } - - /** - * show stack trace dialog when exception throws - * - * @param throwable - * @param parentComponent - * @param title - * @param message - */ - private void showStackTraceDialog(Throwable throwable, Component parentComponent, String title, String message) { - final String more = "More"; - // create stack strace panel - JPanel labelPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - JLabel label = new JLabel(more + ">>"); - labelPanel.add(label); - - JTextArea straceTa = new JTextArea(); - final JScrollPane taPane = new JScrollPane(straceTa); - taPane.setPreferredSize(new Dimension(360, 240)); - taPane.setVisible(false); - // print stack trace into textarea - ByteArrayOutputStream out = new ByteArrayOutputStream(); - throwable.printStackTrace(new PrintStream(out)); - straceTa.setForeground(Color.RED); - straceTa.setText(new String(out.toByteArray())); - - final JPanel stracePanel = new JPanel(new BorderLayout()); - stracePanel.add(labelPanel, BorderLayout.NORTH); - stracePanel.add(taPane, BorderLayout.CENTER); - - label.setForeground(Color.BLUE); - label.setCursor(new Cursor(Cursor.HAND_CURSOR)); - label.addMouseListener(new MouseAdapter() { - public void mouseClicked(MouseEvent e) { - JLabel tmpLab = (JLabel) e.getSource(); - if (tmpLab.getText().equals(more + ">>")) { - tmpLab.setText("<<" + more); - taPane.setVisible(true); - } else { - tmpLab.setText(more + ">>"); - taPane.setVisible(false); - } - SwingUtilities.getWindowAncestor(taPane).pack(); - }; - }); - - JPanel panel = new JPanel(new BorderLayout()); - panel.add(new JLabel(message), BorderLayout.NORTH); - panel.add(stracePanel, BorderLayout.CENTER); - - JOptionPane pane = new JOptionPane(panel, JOptionPane.ERROR_MESSAGE); - JDialog dialog = pane.createDialog(parentComponent, title); - int maxWidth = Toolkit.getDefaultToolkit().getScreenSize().width * 2 / 3; - if (dialog.getWidth() > maxWidth) { - dialog.setSize(new Dimension(maxWidth, dialog.getHeight())); - setLocationRelativeTo(dialog, parentComponent); - } - dialog.setResizable(true); - dialog.setVisible(true); - dialog.dispose(); - } - - private void showStatusInfoDialog(Component parentComponent, String title, String message) { - final String more = "More"; - // create stack strace panel - JPanel labelPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - JLabel label = new JLabel(more + ">>"); - labelPanel.add(label); - - JTextArea straceTa = new JTextArea(); - final JScrollPane taPane = new JScrollPane(straceTa); - taPane.setPreferredSize(new Dimension(360, 240)); - taPane.setVisible(false); - straceTa.setForeground(Color.RED); - straceTa.setText("Status Info"); - - final JPanel stracePanel = new JPanel(new BorderLayout()); - stracePanel.add(labelPanel, BorderLayout.NORTH); - stracePanel.add(taPane, BorderLayout.CENTER); - - label.setForeground(Color.BLUE); - label.setCursor(new Cursor(Cursor.HAND_CURSOR)); - label.addMouseListener(new MouseAdapter() { - public void mouseClicked(MouseEvent e) { - JLabel tmpLab = (JLabel) e.getSource(); - if (tmpLab.getText().equals(more + ">>")) { - tmpLab.setText("<<" + more); - taPane.setVisible(true); - } else { - tmpLab.setText(more + ">>"); - taPane.setVisible(false); - } - SwingUtilities.getWindowAncestor(taPane).pack(); - }; - }); - - JPanel panel = new JPanel(new BorderLayout()); - panel.add(new JLabel(message), BorderLayout.NORTH); - panel.add(stracePanel, BorderLayout.CENTER); - - JOptionPane pane = new JOptionPane(panel, JOptionPane.ERROR_MESSAGE); - JDialog dialog = pane.createDialog(parentComponent, title); - int maxWidth = Toolkit.getDefaultToolkit().getScreenSize().width * 2 / 3; - if (dialog.getWidth() > maxWidth) { - dialog.setSize(new Dimension(maxWidth, dialog.getHeight())); - setLocationRelativeTo(dialog, parentComponent); - } - dialog.setResizable(true); - dialog.setVisible(true); - dialog.dispose(); - } - - private void showEmailStatusInfoDialog(Component parentComponent, String title, String message) { - final String more = "More"; - // create stack strace panel - JPanel labelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - - JButton emailSendButton = new JButton("Send Email"); - - JLabel emailSenderAddressLabel = new JLabel("Sender Email address: "); - JTextField emailSenderAddressInput = new JTextField(4); - emailSenderAddressInput.setPreferredSize(null); - emailSenderAddressInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - emailSendButton.setEnabled(true); - } - }); - - emailSendButton.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - // String result = - // controller.sendStatusInfoEmail(emailSenderAddressInput.getText()); - // statusLabel.setText(result); - } - }); - emailSendButton.setEnabled(false); - - labelPanel.add(emailSenderAddressLabel); - labelPanel.add(emailSenderAddressInput); - labelPanel.add(emailSendButton); - - JPanel panel = new JPanel(new BorderLayout()); - panel.add(labelPanel, BorderLayout.CENTER); - - JOptionPane pane = new JOptionPane(panel, JOptionPane.INFORMATION_MESSAGE); - JDialog dialog = pane.createDialog(parentComponent, title); - int maxWidth = Toolkit.getDefaultToolkit().getScreenSize().width * 2 / 3; - if (dialog.getWidth() > maxWidth) { - dialog.setSize(new Dimension(maxWidth, dialog.getHeight())); - setLocationRelativeTo(dialog, parentComponent); - } - dialog.setResizable(true); - dialog.setVisible(true); - dialog.dispose(); - } - - /** - * set c1 location relative to c2 - * - * @param c1 - * @param c2 - */ - private void setLocationRelativeTo(Component c1, Component c2) { - Container root = null; - - if (c2 != null) { - if (c2 instanceof Window) { - root = (Container) c2; - } else { - Container parent; - for (parent = c2.getParent(); parent != null; parent = parent.getParent()) { - if (parent instanceof Window) { - root = parent; - break; - } - } - } - } - - if ((c2 != null && !c2.isShowing()) || root == null || !root.isShowing()) { - Dimension paneSize = c1.getSize(); - - Point centerPoint = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint(); - c1.setLocation(centerPoint.x - paneSize.width / 2, centerPoint.y - paneSize.height / 2); - } else { - Dimension invokerSize = c2.getSize(); - Point invokerScreenLocation = c2.getLocation(); // by longrm: - // c2.getLocationOnScreen(); - - Rectangle windowBounds = c1.getBounds(); - int dx = invokerScreenLocation.x + ((invokerSize.width - windowBounds.width) >> 1); - int dy = invokerScreenLocation.y + ((invokerSize.height - windowBounds.height) >> 1); - Rectangle ss = root.getGraphicsConfiguration().getBounds(); - - // Adjust for bottom edge being offscreen - if (dy + windowBounds.height > ss.y + ss.height) { - dy = ss.y + ss.height - windowBounds.height; - if (invokerScreenLocation.x - ss.x + invokerSize.width / 2 < ss.width / 2) { - dx = invokerScreenLocation.x + invokerSize.width; - } else { - dx = invokerScreenLocation.x - windowBounds.width; - } - } - - // Avoid being placed off the edge of the screen - if (dx + windowBounds.width > ss.x + ss.width) { - dx = ss.x + ss.width - windowBounds.width; - } - if (dx < ss.x) - dx = ss.x; - if (dy < ss.y) - dy = ss.y; - - c1.setLocation(dx, dy); - } - } - - private void buildContent() { - - contentPane = new JPanel(); - - upperPane = new JPanel(); - JPanel statusPane = new JPanel(); - JPanel lowerPane = new JPanel(); - - statusLabel = new JLabel("Ready"); - JButton showStatusInfoButton = new JButton("Show Status Info"); - - showStatusInfoButton.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - String s = e.getActionCommand(); - Throwable t = workspace.getInstrumentSessionManager().getCurrentSession().getException(); - if (t != null) { - showStackTraceDialog(t, "StatusInfo", "Instrument Exception"); - } else { - showStatusInfoDialog("StatusInfo", "Instrument OK"); - } - } - }); - - statusLabel = new JLabel("Ready"); - - JButton dumpStatusInfoButton = new JButton("Dump Status Info"); - - dumpStatusInfoButton.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - String result = controller.dumpStatusInfo(); - statusLabel.setText(result); - } - }); - - contentPane.setLayout(new BorderLayout()); - - final int inset1 = 45; - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - contentPane.setPreferredSize(new Dimension(screenSize.width - inset1 * 2, screenSize.height - inset1 * 2)); - - EmptyBorder eb = new EmptyBorder(5, 5, 5, 5); - BevelBorder bb = new BevelBorder(BevelBorder.LOWERED); - CompoundBorder cb = new CompoundBorder(eb, bb); - contentPane.setBorder(cb); - - fileNameLabel = new JLabel(""); - - statusPane.add(showStatusInfoButton, BorderLayout.WEST); - statusPane.add(dumpStatusInfoButton, BorderLayout.WEST); - statusPane.add(statusLabel, BorderLayout.CENTER); - statusPane.add(new JLabel(" Current File:"), BorderLayout.EAST); - statusPane.add(fileNameLabel, BorderLayout.EAST); - - EmptyBorder eb1 = new EmptyBorder(2, 2, 2, 2); - BevelBorder bb1 = new BevelBorder(BevelBorder.LOWERED); - CompoundBorder cb1 = new CompoundBorder(eb1, bb1); - statusPane.setBorder(cb1); - - upperPane.setLayout(new BorderLayout()); - - lowerPane.setLayout(new BorderLayout()); - lowerPane.add(statusPane, BorderLayout.CENTER); - - contentPane.add(upperPane, BorderLayout.CENTER); - contentPane.add(lowerPane, BorderLayout.SOUTH); - contentPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); - - mainFrame.setContentPane(contentPane); - } - - public void initialise(JFrame mainframe) { - visorPanel = new JPanel(); - this.mainframe = mainframe; - this.visorPanel.setLayout(new BorderLayout()); - JPanel topPanel = buildTopPanel(); - JPanel bottomPanel = buildBottomPanel(); - JScrollPane graphPanel = buildGraphPanel(); - this.visorPanel.add(topPanel, BorderLayout.NORTH); - this.visorPanel.add(graphPanel, BorderLayout.CENTER); - this.visorPanel.add(bottomPanel, BorderLayout.SOUTH); - } - - private JPanel buildTopPanel() { - - JPanel panel = new JPanel(new GridLayout(1, 1)); - - JPanel controlPanel = buildControlPanel(); - panel.add(controlPanel); - - return panel; - } - - private JPanel buildBottomPanel() { - - JPanel panel = new JPanel(new GridLayout(1, 1)); - - JPanel viewControlPanel = buildViewControlPanel(); - panel.add(viewControlPanel); - - return panel; - } - - private JScrollPane buildGraphPanel() { - JPanel panel = new JPanel(); - panel.setLayout(new GridLayout(1, 1)); - - JPanel leftGraphPanel = new JPanel(); - leftGraphPanel.setLayout(new BorderLayout()); - - JPanel rightGraphPanel = new JPanel(); - rightGraphPanel.setLayout(new BorderLayout()); - - JSplitPane splitPane = new JSplitPane(SwingConstants.VERTICAL, new JScrollPane(leftGraphPanel), - new JScrollPane(rightGraphPanel)); - - Toolkit myScreen = Toolkit.getDefaultToolkit(); - Dimension screenSize = myScreen.getScreenSize(); - int screenHeight = screenSize.height; - int screenWidth = screenSize.width; - - splitPane.setOneTouchExpandable(true); - splitPane.setDividerLocation((int) ((double) screenWidth * 0.7)); - - JPanel chromaPanel = buildChromaPanel(); - JPanel spectrumsPanel = buildSpectrumsPanel(); - JPanel beatsPanel = buildBeatsPanel(); - toneMapViewTopPane = new JSplitPane(SwingConstants.HORIZONTAL, new JScrollPane(chromaPanel), - new JScrollPane(beatsPanel)); - toneMapViewBottomPane = new JSplitPane(SwingConstants.HORIZONTAL, new JScrollPane(toneMapViewTopPane), - new JScrollPane(spectrumsPanel)); - toneMapViewTopPane.setOneTouchExpandable(true); - toneMapViewBottomPane.setOneTouchExpandable(true); - - leftGraphPanel.add(toneMapViewBottomPane, BorderLayout.CENTER); - - if (toneMapViewTopPane != null) { - if (parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_CHORDS)) { - if (parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_BEATS)) { - toneMapViewBottomPane.setDividerLocation((int) ((double) screenHeight * 0.3)); - toneMapViewTopPane.setDividerLocation((int) ((double) screenHeight * 0.18)); - } else { - toneMapViewBottomPane.setDividerLocation((int) ((double) screenHeight * 0.3)); - toneMapViewTopPane.setDividerLocation((int) ((double) screenHeight * 0.18)); - } - } else { - if (parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_BEATS)) { - toneMapViewBottomPane.setDividerLocation((int) ((double) screenHeight * 0.2)); - toneMapViewTopPane.setDividerLocation(0); - } else { - toneMapViewBottomPane.setDividerLocation(0); - toneMapViewTopPane.setDividerLocation(0); - } - } - } - diagnosticsPanel = buildDiagnosticsPanel(); - rightGraphPanel.add(diagnosticsPanel, BorderLayout.CENTER); - Dimension minimumSize = new Dimension(100, 1000); - panel.setMinimumSize(minimumSize); - panel.add(splitPane); - return new JScrollPane(panel); - } - - private JPanel buildSpectrumsPanel() { - JPanel panel = new JPanel(new BorderLayout()); - JTabbedPane toneMapTabbedPane = new JTabbedPane(); - toneMapTabbedPane - .setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(10, 10, 10, 10), new EtchedBorder())); // BorderFactory.createLineBorder(Color.black)); - JPanel toneMapLayerPanel = createToneMapLayerPanel(); - toneMapTabbedPane.addTab("ToneMap", toneMapLayerPanel); - cqPanel = createCQPanel(); - toneMapTabbedPane.addTab("CQ", cqPanel); - pitchDetectPanel = createPitchDetectPanel(); - toneMapTabbedPane.addTab("Pitch", pitchDetectPanel); - panel.add(toneMapTabbedPane, BorderLayout.CENTER); - return panel; - } - - private JPanel buildChromaPanel() { - JPanel panel = new JPanel(new BorderLayout()); - JTabbedPane chromaTabbedPane = new JTabbedPane(); - chromaTabbedPane - .setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(10, 10, 10, 10), new EtchedBorder())); - chromaView = new ChromaView(); - JPanel chromaSynthPanel = new JPanel(new BorderLayout()); - chromaSynthPanel.add(chromaView, BorderLayout.CENTER); - chromaSynthPanel.setBackground(Color.BLACK); - chromaTabbedPane.addTab("Chroma", chromaSynthPanel); - panel.add(chromaTabbedPane, BorderLayout.CENTER); - return panel; - } - - private JPanel buildBeatsPanel() { - JPanel panel = new JPanel(new BorderLayout()); - JTabbedPane beatsTabbedPane = new JTabbedPane(); - beatsTabbedPane - .setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(10, 10, 10, 10), new EtchedBorder())); // BorderFactory.createLineBorder(Color.black)); - - beatsView = new BeatsView(); - JPanel beatsPanel = new JPanel(new BorderLayout()); - beatsPanel.add(beatsView, BorderLayout.CENTER); - beatsPanel.setBackground(Color.BLACK); - beatsTabbedPane.addTab("Beats", beatsPanel); - - panel.add(beatsTabbedPane, BorderLayout.CENTER); - return panel; - } - - private JPanel buildDiagnosticsPanel() { - JPanel panel = new JPanel(new BorderLayout()); - JTabbedPane diagnosticsTabbedPane = new JTabbedPane(); - diagnosticsTabbedPane - .setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(10, 10, 10, 10), new EtchedBorder())); // BorderFactory.createLineBorder(Color.black)); - timeFramePanel = new TimeFramePanel(); - diagnosticsTabbedPane.addTab("ToneMap Frame", timeFramePanel); - spectrumPanel = createSpectrumPanel(); - diagnosticsTabbedPane.addTab("Spectrum", spectrumPanel); - panel.add(diagnosticsTabbedPane, BorderLayout.CENTER); - return panel; - } - - public String getCurrentLocalDateTimeStamp() { - return LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd_HH:mm:ss.SSS")); - } - - private JPanel buildViewControlPanel() { - - JPanel panel = new JPanel(new BorderLayout()); - panel.setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(10, 10, 10, 10), new EtchedBorder())); - - JPanel graphControlPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - - JPanel graphViewControlPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - - JLabel frameNumberLabel = new JLabel("Frame #: "); - frameNumberInput = new JTextField(4); - frameNumberInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JTextField textField = (JTextField) e.getSource(); - String newValue = textField.getText(); - int frame = Integer.valueOf(newValue); - if (frame < 1) { - frameNumberInput.setText("1"); - } - showFrame(Integer.valueOf(newValue)); - } - }); - frameNumberInput.setText("0"); - graphControlPanel.add(frameNumberLabel); - graphControlPanel.add(frameNumberInput); - - toneMapViewComboBox = new JComboBox<>(); - - if (parameterManager - .getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_TONEMAP_PERSISTENCE_MODE) <= 2) { - Arrays.asList(toneMapViewTypesMode2).stream().forEach(entry -> toneMapViewComboBox.addItem(entry)); - } else { - Arrays.asList(toneMapViewTypesMode3).stream().forEach(entry -> toneMapViewComboBox.addItem(entry)); - } - - toneMapViewComboBox.setEnabled(false); - toneMapViewComboBox.setSelectedItem(Cell.CellTypes.AUDIO_SYNTHESIS.name()); - toneMapViewComboBox.setEnabled(true); - currentToneMapViewType = Cell.CellTypes.AUDIO_SYNTHESIS.name(); - - toneMapViewComboBox.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - String value = String.valueOf(toneMapViewComboBox.getSelectedItem()); - if (value != null) { - currentToneMapViewType = value; - switchToneMapView(); - } - } - }); - - graphControlPanel.add(new JLabel("ToneMap View: ")); - graphControlPanel.add(toneMapViewComboBox); - - JLabel timeAxisOffsetLabel = new JLabel("Time Axis Offset ms: "); - timeAxisOffsetInput = new JTextField(4); - timeAxisOffsetInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JTextField textField = (JTextField) e.getSource(); - String newValue = textField.getText(); - newValue = parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_OFFSET, - newValue); - textField.setText(newValue); - refreshMapViews(); - switchToneMapView(); - } - }); - - timeAxisOffsetInput - .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_OFFSET)); - graphControlPanel.add(timeAxisOffsetLabel); - graphControlPanel.add(timeAxisOffsetInput); - - JLabel pitchAxisOffsetLabel = new JLabel("Pitch Axis Offset ms: "); - pitchAxisOffsetInput = new JTextField(4); - pitchAxisOffsetInput.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - JTextField textField = (JTextField) e.getSource(); - String newValue = textField.getText(); - newValue = parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_PITCH_AXIS_OFFSET, - newValue); - textField.setText(newValue); - refreshMapViews(); - } - }); - - pitchAxisOffsetInput - .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_VIEW_PITCH_AXIS_OFFSET)); - graphControlPanel.add(pitchAxisOffsetLabel); - graphControlPanel.add(pitchAxisOffsetInput); - - JLabel timeAxisRangeLabel = new JLabel("Time Axis Range ms: "); - timeAxisRangeInput = new JTextField(4); - timeAxisRangeInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JTextField textField = (JTextField) e.getSource(); - String newValue = textField.getText(); - newValue = parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_RANGE, - newValue); - textField.setText(newValue); - refreshMapViews(); - - } - }); - timeAxisRangeInput - .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_RANGE)); - graphControlPanel.add(timeAxisRangeLabel); - graphControlPanel.add(timeAxisRangeInput); - - JLabel pitchAxisRangeLabel = new JLabel("Pitch Axis Range ms: "); - pitchAxisRangeInput = new JTextField(4); - pitchAxisRangeInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JTextField textField = (JTextField) e.getSource(); - String newValue = textField.getText(); - newValue = parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_PITCH_AXIS_RANGE, - newValue); - textField.setText(newValue); - refreshMapViews(); - } - }); - - pitchAxisRangeInput - .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_VIEW_PITCH_AXIS_RANGE)); - graphControlPanel.add(pitchAxisRangeLabel); - graphControlPanel.add(pitchAxisRangeInput); - - panel.add(graphControlPanel, BorderLayout.NORTH); - - showColourSwitchCB = new JCheckBox("showColourSwitchCB"); - showColourSwitchCB.setText("Colour"); - showColourSwitchCB.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - JCheckBox cb = (JCheckBox) e.getSource(); - boolean newValue = cb.isSelected(); - parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_COLOUR, - Boolean.toString(newValue)); - refreshMapViews(); - } - }); - showColourSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_COLOUR)); - graphViewControlPanel.add(showColourSwitchCB); - - showPeaksSwitchCB = new JCheckBox("showPeaksSwitchCB"); - showPeaksSwitchCB.setText("Peaks"); - showPeaksSwitchCB.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - JCheckBox cb = (JCheckBox) e.getSource(); - boolean newValue = cb.isSelected(); - parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_PEAKS, - Boolean.toString(newValue)); - refreshMapViews(); - } - }); - showPeaksSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_PEAKS)); - graphViewControlPanel.add(showPeaksSwitchCB); - - showPowerSwitchCB = new JCheckBox("showPowerSwitchCB"); - showPowerSwitchCB.setText("Power"); - showPowerSwitchCB.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - JCheckBox cb = (JCheckBox) e.getSource(); - boolean newValue = cb.isSelected(); - parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_POWER, - Boolean.toString(newValue)); - refreshMapViews(); - } - }); - showPowerSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_POWER)); - graphViewControlPanel.add(showPowerSwitchCB); - - showNotesSwitchCB = new JCheckBox("showNotesSwitchCB"); - showNotesSwitchCB.setText("Notes"); - showNotesSwitchCB.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - JCheckBox cb = (JCheckBox) e.getSource(); - boolean newValue = cb.isSelected(); - parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_NOTES, - Boolean.toString(newValue)); - refreshMapViews(); - } - }); - showNotesSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_NOTES)); - graphViewControlPanel.add(showNotesSwitchCB); - - showChordsSwitchCB = new JCheckBox("showChordsSwitchCB"); - showChordsSwitchCB.setText("Chords"); - showChordsSwitchCB.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - JCheckBox cb = (JCheckBox) e.getSource(); - boolean newValue = cb.isSelected(); - parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_CHORDS, - Boolean.toString(newValue)); - Toolkit myScreen = Toolkit.getDefaultToolkit(); - Dimension screenSize = myScreen.getScreenSize(); - int screenHeight = screenSize.height; - if (toneMapViewTopPane != null) { - if (parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_CHORDS)) { - if (parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_BEATS)) { - toneMapViewBottomPane.setDividerLocation((int) ((double) screenHeight * 0.3)); - toneMapViewTopPane.setDividerLocation((int) ((double) screenHeight * 0.18)); - } else { - toneMapViewBottomPane.setDividerLocation((int) ((double) screenHeight * 0.3)); - toneMapViewTopPane.setDividerLocation((int) ((double) screenHeight * 0.18)); - } - } else { - if (parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_BEATS)) { - toneMapViewBottomPane.setDividerLocation((int) ((double) screenHeight * 0.2)); - toneMapViewTopPane.setDividerLocation(0); - } else { - toneMapViewBottomPane.setDividerLocation(0); - toneMapViewTopPane.setDividerLocation(0); - } - } - } - refreshMapViews(); - } - }); - showChordsSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_CHORDS)); - graphViewControlPanel.add(showChordsSwitchCB); - - showBaseSwitchCB = new JCheckBox("showBaseSwitchCB"); - showBaseSwitchCB.setText("Base"); - showBaseSwitchCB.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - JCheckBox cb = (JCheckBox) e.getSource(); - boolean newValue = cb.isSelected(); - parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_BASE, - Boolean.toString(newValue)); - refreshMapViews(); - } - }); - showBaseSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_BASE)); - graphViewControlPanel.add(showBaseSwitchCB); - - showBeatsSwitchCB = new JCheckBox("showBeatsSwitchCB"); - showBeatsSwitchCB.setText("Beats"); - showBeatsSwitchCB.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - JCheckBox cb = (JCheckBox) e.getSource(); - boolean newValue = cb.isSelected(); - parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_BEATS, - Boolean.toString(newValue)); - Toolkit myScreen = Toolkit.getDefaultToolkit(); - Dimension screenSize = myScreen.getScreenSize(); - int screenHeight = screenSize.height; - if (toneMapViewTopPane != null) { - if (parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_CHORDS)) { - if (parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_BEATS)) { - toneMapViewBottomPane.setDividerLocation((int) ((double) screenHeight * 0.3)); - toneMapViewTopPane.setDividerLocation((int) ((double) screenHeight * 0.18)); - } else { - toneMapViewBottomPane.setDividerLocation((int) ((double) screenHeight * 0.3)); - toneMapViewTopPane.setDividerLocation((int) ((double) screenHeight * 0.18)); - } - } else { - if (parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_BEATS)) { - toneMapViewBottomPane.setDividerLocation((int) ((double) screenHeight * 0.2)); - toneMapViewTopPane.setDividerLocation(0); - } else { - toneMapViewBottomPane.setDividerLocation(0); - toneMapViewTopPane.setDividerLocation(0); - } - } - } - refreshMapViews(); - } - }); - showBeatsSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_BEATS)); - graphViewControlPanel.add(showBeatsSwitchCB); - - showStatsSwitchCB = new JCheckBox("showStatsSwitchCB"); - showStatsSwitchCB.setText("Stats"); - showStatsSwitchCB.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - JCheckBox cb = (JCheckBox) e.getSource(); - boolean newValue = cb.isSelected(); - parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_STATS, - Boolean.toString(newValue)); - refreshMapViews(); - } - }); - showStatsSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_STATS)); - graphViewControlPanel.add(showStatsSwitchCB); - - showLogSwitchCB = new JCheckBox("showLogSwitchCB"); - showLogSwitchCB.setText("Logn"); - showLogSwitchCB.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - JCheckBox cb = (JCheckBox) e.getSource(); - boolean newValue = cb.isSelected(); - parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_LOG, - Boolean.toString(newValue)); - refreshMapViews(); - } - }); - showLogSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_LOG)); - graphViewControlPanel.add(showLogSwitchCB); - - updateViewButton = new JButton("Update"); - updateViewButton.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - updateViewThresholds(); - toneMapViewHighThresholdInput.setText( - parameterManager.getParameter(InstrumentParameterNames.MONITOR_TONEMAP_VIEW_HIGH_THRESHOLD)); - } - }); - graphViewControlPanel.add(updateViewButton); - - JLabel toneMapViewLowThresholdLabel = new JLabel("Low: "); - toneMapViewLowThresholdInput = new JTextField(4); - toneMapViewLowThresholdInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JTextField textField = (JTextField) e.getSource(); - String newValue = textField.getText(); - newValue = parameterManager.setParameter(InstrumentParameterNames.MONITOR_TONEMAP_VIEW_LOW_THRESHOLD, - newValue); - textField.setText(newValue); - refreshMapViews(); - } - }); - - toneMapViewLowThresholdInput - .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_TONEMAP_VIEW_LOW_THRESHOLD)); - graphViewControlPanel.add(toneMapViewLowThresholdLabel); - graphViewControlPanel.add(toneMapViewLowThresholdInput); - - JLabel toneMapViewHighThresholdLabel = new JLabel("High: "); - toneMapViewHighThresholdInput = new JTextField(4); - toneMapViewHighThresholdInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JTextField textField = (JTextField) e.getSource(); - String newValue = textField.getText(); - newValue = parameterManager.setParameter(InstrumentParameterNames.MONITOR_TONEMAP_VIEW_HIGH_THRESHOLD, - newValue); - textField.setText(newValue); - refreshMapViews(); - } - }); - - toneMapViewHighThresholdInput - .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_TONEMAP_VIEW_HIGH_THRESHOLD)); - graphViewControlPanel.add(toneMapViewHighThresholdLabel); - graphViewControlPanel.add(toneMapViewHighThresholdInput); - - panel.add(graphViewControlPanel, BorderLayout.CENTER); - - return panel; - } - - @Override - public 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(); - parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_OFFSET, "0"); - int timeRange = toneMapView.getMaxTime(); - formatter = new Formatter(); - formatter.format("%d", timeRange); - parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_RANGE, formatter.toString()); - formatter.close(); - int minPitchCents = toneMapView.getMinPitchCents(); - formatter = new Formatter(); - formatter.format("%d", minPitchCents); - // parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_PITCH_AXIS_OFFSET, - // formatter.toString()); - formatter.close(); - int maxPitchCents = toneMapView.getMaxPitchCents(); - formatter = new Formatter(); - formatter.format("%d", maxPitchCents); - // parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_PITCH_AXIS_RANGE, - // formatter.toString()); - formatter.close(); - timeAxisOffsetInput - .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_OFFSET)); - // pitchAxisOffsetInput - // .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_VIEW_PITCH_AXIS_OFFSET)); - timeAxisRangeInput - .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_RANGE)); - // pitchAxisRangeInput - // .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_VIEW_PITCH_AXIS_RANGE)); - - } - refreshMapViews(); - } - - protected boolean parseIntsegerTextField(JTextField textField, int min, int max, String parameterName) { - try { - int value = Integer.parseInt(textField.getText()); - if (value >= min && value <= max) { - parameterManager.setParameter(parameterName, Integer.toString(value)); - return true; - } else { - textField.setText(parameterManager.getParameter(parameterName)); - } - } catch (Exception ex) { - textField.setText(parameterManager.getParameter(parameterName)); - } - return false; - } - - private JPanel buildControlPanel() { - - JPanel panel = new JPanel(new BorderLayout()); - panel.setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(10, 10, 10, 10), new EtchedBorder())); - - JPanel actionPanel = new JPanel(new BorderLayout()); - // JPanel actionPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - - JPanel actionEastPanel = new JPanel(); - JPanel actionCenterPanel = new JPanel(); - JPanel actionWestPanel = new JPanel(); - actionPanel.add(actionEastPanel, BorderLayout.EAST); - actionPanel.add(actionCenterPanel, BorderLayout.CENTER); - actionPanel.add(actionWestPanel, BorderLayout.WEST); - - JPanel voicePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - - JPanel instrumentPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - - resetSystemButton = new JButton("Reset"); - resetSystemButton.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent arg0) { - instrument.reset(); - updateStatusMessage("System Reset"); - } - }); - - actionWestPanel.add(resetSystemButton); - - final JButton helpButton = new JButton("Help"); - - helpButton.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - String s = e.getActionCommand(); - String message = """ - For information about using this application - please see - https://github.com/jimomulloy/instrument/wiki - - In case of status errors, please use the "Dump Status Info" button to create a text file containing information - about the current status of the application. - - If you wish me to investigate please send this file as an attachment to my email address jimomulloy@gmail.com. - - Thank you for using this early prototype version, hope you have fun with it. - """; - if (s.equals("Help")) { - JOptionPane.showMessageDialog(mainframe, message); - } - } - }); - actionWestPanel.add(helpButton); - - parametersButton = new JButton("Parameters"); - - parameterDialog = new JDialog(mainframe, "Parameters"); - parameterDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); - parameterDialog.addWindowListener(new WindowAdapter() { - public void windowClosed(WindowEvent e) { - parameterDialogOpen = false; - } - - public void windowClosing(WindowEvent e) { - parameterDialogOpen = false; - parameterDialog.getContentPane().removeAll(); - parameterDialog.dispose(); - } - }); - parametersButton.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - String s = e.getActionCommand(); - if (s.equals("Parameters")) { - - if (!parameterDialogOpen) { - parameterDialog.getContentPane().removeAll(); - - JPanel dialogPanel = new JPanel(new BorderLayout()); - - parameterPanel = new ParametersPanel(); - - dialogPanel.setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(20, 20, 20, 20), - new EtchedBorder())); - - dialogPanel.add(new JScrollPane(parameterPanel), BorderLayout.CENTER); - - parameterDialog.add(dialogPanel); - - Toolkit myScreen = Toolkit.getDefaultToolkit(); - Dimension screenSize = myScreen.getScreenSize(); - int screenHeight = screenSize.height; - int screenWidth = screenSize.width; - - parameterDialog.setSize((int) ((double) screenWidth * 0.7), - (int) ((double) screenHeight * 0.7)); - - parameterDialog.setVisible(true); - - parameterDialog.pack(); - - parameterDialogOpen = true; - - } - } - } - }); - - actionWestPanel.add(parametersButton); - - synthButton = new JButton("Synth Controls"); - - synthDialog = new JDialog(mainframe, "Synth"); - synthDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); - synthDialog.addWindowListener(new WindowAdapter() { - public void windowClosed(WindowEvent e) { - synthDialogOpen = false; - } - - public void windowClosing(WindowEvent e) { - synthDialogOpen = false; - synthDialog.getContentPane().removeAll(); - synthDialog.dispose(); - } - }); - synthButton.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - String s = e.getActionCommand(); - if (s.equals("Synth Controls")) { - - if (!synthDialogOpen) { - synthDialog.getContentPane().removeAll(); - - JPanel dialogPanel = new JPanel(new BorderLayout()); - - synthPanel = new SynthPanel(); - dialogPanel.setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(20, 20, 20, 20), - new EtchedBorder())); - - dialogPanel.add(new JScrollPane(synthPanel), BorderLayout.CENTER); - - synthDialog.add(dialogPanel); - - Toolkit myScreen = Toolkit.getDefaultToolkit(); - Dimension screenSize = myScreen.getScreenSize(); - int screenHeight = screenSize.height; - int screenWidth = screenSize.width; - - synthDialog.setSize((int) ((double) screenWidth * 0.7), (int) ((double) screenHeight * 0.7)); - - synthDialog.setVisible(true); - - synthDialog.pack(); - - synthDialogOpen = true; - - } - } - } - }); - actionWestPanel.add(synthButton); - - final JFileChooser fileChooser = new JFileChooser(new File(getAudioSourceFileFolder())); - chooseFileButton = new JButton("Open"); - startFileProcessingButton = new JButton("Start"); - startListeningButton = new JButton("Listen"); - stopListeningButton = new JButton("Stop"); - playAudioButton = new JButton("Play Audio"); - playStreamButton = new JButton("Play Stream"); - fileChooser.setSelectedFile(new File(getAudioSourceFileFolder(), getDefaultAudioFile())); - chooseFileButton.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent arg0) { - int returnVal = fileChooser.showOpenDialog(visorPanel); - if (returnVal == JFileChooser.APPROVE_OPTION) { - inputFile = fileChooser.getSelectedFile(); - String fileName = inputFile.getAbsolutePath(); - fileNameLabel.setText(inputFile.getName()); - startListeningButton.setEnabled(false); - startFileProcessingButton.setEnabled(false); - stopListeningButton.setEnabled(true); - chooseFileButton.setEnabled(false); - frameNumberInput.setEnabled(false); - // timeAxisOffsetInput.setText("0"); - workspace.getInstrumentSessionManager().getCurrentSession().clearException(); - parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_OFFSET, "0"); - parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_DEFAULT_FILE, - inputFile.getName()); - toneMapViews.remove(currentToneMapViewType); - refreshMapViews(); - resetToneMapView(); - try { - Instrument.getInstance().getCoordinator().getHearing().startAudioFileStream(fileName); - updateStatusMessage("Choosen file: " + inputFile); - } catch (Exception e) { - LOG.log(Level.SEVERE, "Error choosing file :" + inputFile, e); - coordinator.getHearing().stopAudioStream(); - coordinator.getVoice().clear(coordinator.getHearing().getStreamId()); - startFileProcessingButton.setEnabled(true); - startListeningButton.setEnabled(true); - // stopListeningButton.setEnabled(false); - chooseFileButton.setEnabled(true); - frameNumberInput.setEnabled(true); - updateStatusMessage("Error choosing file :" + inputFile + ", " + e.getMessage()); - } - } - } - }); - - actionCenterPanel.add(chooseFileButton); - - startFileProcessingButton.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent arg0) { - try { - inputFile = fileChooser.getSelectedFile(); - String fileName = inputFile.getAbsolutePath(); - fileNameLabel.setText(inputFile.getName()); - startListeningButton.setEnabled(false); - startFileProcessingButton.setEnabled(false); - stopListeningButton.setEnabled(true); - chooseFileButton.setEnabled(false); - frameNumberInput.setEnabled(false); - // timeAxisOffsetInput.setText("0"); - workspace.getInstrumentSessionManager().getCurrentSession().clearException(); - parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_OFFSET, "0"); - parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_DEFAULT_FILE, - inputFile.getName()); - toneMapViews.remove(currentToneMapViewType); - refreshMapViews(); - resetToneMapView(); - Instrument.getInstance().getCoordinator().getHearing().startAudioFileStream(fileName); - updateStatusMessage("Started file: " + inputFile); - } catch (Exception e) { - LOG.log(Level.SEVERE, "Error starting file :" + inputFile, e); - coordinator.getHearing().stopAudioStream(); - coordinator.getVoice().clear(coordinator.getHearing().getStreamId()); - startFileProcessingButton.setEnabled(true); - startListeningButton.setEnabled(true); - // stopListeningButton.setEnabled(false); - chooseFileButton.setEnabled(true); - frameNumberInput.setEnabled(true); - updateStatusMessage("Error starting file :" + inputFile + ", " + e.getMessage()); - } - } - }); - - startListeningButton.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent arg0) { - try { - String fileName = "instrument_recording_" + System.currentTimeMillis() + ".wav"; - String filePath = getAudioRecordFileFolder() + "/" + fileName; - startListeningButton.setEnabled(false); - startFileProcessingButton.setEnabled(false); - fileNameLabel.setText(fileName); - stopListeningButton.setEnabled(true); - chooseFileButton.setEnabled(false); - frameNumberInput.setEnabled(false); - // timeAxisOffsetInput.setText("0"); - workspace.getInstrumentSessionManager().getCurrentSession().clearException(); - parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_OFFSET, "0"); - toneMapViews.remove(currentToneMapViewType); - - if (coordinator.getHearing().getStreamId() != null) { - coordinator.getHearing().stopAudioStream(); - coordinator.getHearing().stopAudioPlayer(); - coordinator.getVoice().clear(coordinator.getHearing().getStreamId()); - coordinator.getVoice().stopStreamPlayer(); - } - - refreshMapViews(); - resetToneMapView(); - - coordinator.getHearing().startAudioLineStream(filePath); - updateStatusMessage("Started listener: " + fileName); - - } catch (LineUnavailableException | IOException e) { - LOG.log(Level.SEVERE, "Error starting listener", e); - coordinator.getHearing().stopAudioStream(); - coordinator.getVoice().clear(coordinator.getHearing().getStreamId()); - startFileProcessingButton.setEnabled(true); - startListeningButton.setEnabled(true); - chooseFileButton.setEnabled(true); - frameNumberInput.setEnabled(true); - updateStatusMessage("Error starting listener :" + e.getMessage()); - } - } - }); - - stopListeningButton.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent arg0) { - new Thread(() -> { - coordinator.getHearing().stopAudioStream(); - coordinator.getHearing().stopAudioPlayer(); - coordinator.getVoice().clear(coordinator.getHearing().getStreamId()); - coordinator.getVoice().stopStreamPlayer(); - }).start(); - startFileProcessingButton.setEnabled(true); - startListeningButton.setEnabled(true); - playAudioButton.setEnabled(true); - playStreamButton.setEnabled(true); - chooseFileButton.setEnabled(true); - frameNumberInput.setEnabled(true); - updateStatusMessage("Stopped"); - } - }); - - playAudioButton.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent arg0) { - try { - boolean started = coordinator.getHearing().startAudioPlayer(); - if (started) { - stopListeningButton.setEnabled(true); - } - } catch (Exception e) { - LOG.log(Level.SEVERE, "Error starting listener", e); - coordinator.getHearing().stopAudioStream(); - updateStatusMessage("Error playing audio :" + e.getMessage()); - } - } - }); - - playStreamButton.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent arg0) { - if (coordinator.getHearing().getStreamId() != null) { - int index = parameterManager - .getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_STREAM_SAVE_INDEX); - final ToneMap synthToneMap = workspace.getAtlas().getSavedToneMap(index); - LOG.severe(">>PLAY ST: " + index + ", " + synthToneMap); - if (synthToneMap != null) { - playStreamButton.setEnabled(false); - new Thread(() -> { - coordinator.getVoice().startStreamPlayer(synthToneMap.getStreamId(), synthToneMap); - }).start(); - stopListeningButton.setEnabled(true); - } - } - } - }); - - actionCenterPanel.add(startFileProcessingButton); - actionCenterPanel.add(startListeningButton); - actionCenterPanel.add(stopListeningButton); - actionCenterPanel.add(playAudioButton); - actionCenterPanel.add(playStreamButton); - playStreamButton.setEnabled(false); - - streamSaveSwitchCB = new JCheckBox("streamSaveSwitchCB"); - streamSaveSwitchCB.setText("Save"); - streamSaveSwitchCB.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - JCheckBox cb = (JCheckBox) e.getSource(); - boolean newValue = cb.isSelected(); - parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_STREAM_SAVE_SWITCH, - Boolean.toString(newValue)); - refreshMapViews(); - } - }); - streamSaveSwitchCB.setSelected( - parameterManager.getBooleanParameter(InstrumentParameterNames.PERCEPTION_HEARING_STREAM_SAVE_SWITCH)); - actionCenterPanel.add(streamSaveSwitchCB); - - cortexShortCircuitSwitchCB = new JCheckBox("cortexShortCircuitSwitchCB"); - cortexShortCircuitSwitchCB.setText("Short"); - cortexShortCircuitSwitchCB.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - JCheckBox cb = (JCheckBox) e.getSource(); - boolean newValue = cb.isSelected(); - parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_CORTEX_SHORT_CIRCUIT_SWITCH, - Boolean.toString(newValue)); - if (newValue) { - parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_SYNTHESIS_SWEEP_RANGE, - Integer.toString(10)); - parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_NOTATE_SWEEP_RANGE, - Integer.toString(20)); - parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_SINK_SWEEP_RANGE, - Integer.toString(0)); - } else { - parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_SYNTHESIS_SWEEP_RANGE, - Integer.toString(20)); - parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_NOTATE_SWEEP_RANGE, - Integer.toString(50)); - parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_SINK_SWEEP_RANGE, - Integer.toString(0)); - - } - refreshMapViews(); - } - }); - cortexShortCircuitSwitchCB.setSelected( - parameterManager.getBooleanParameter(InstrumentParameterNames.PERCEPTION_CORTEX_SHORT_CIRCUIT_SWITCH)); - actionCenterPanel.add(cortexShortCircuitSwitchCB); - - JLabel streamIndexLabel = new JLabel("Index: "); - streamIndexInput = new JTextField(4); - streamIndexInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - String newValue = streamIndexInput.getText(); - newValue = parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_STREAM_SAVE_INDEX, - newValue); - streamIndexInput.setText(newValue); - } - }); - streamIndexInput - .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_STREAM_SAVE_INDEX)); - actionCenterPanel.add(streamIndexLabel); - actionCenterPanel.add(streamIndexInput); - - JLabel playStartOffsetLabel = new JLabel("Start Offset: "); - playStartOffsetInput = new JTextField(4); - playStartOffsetInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - String newValue = playStartOffsetInput.getText(); - newValue = parameterManager - .setParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY_START_OFFSET, newValue); - playStartOffsetInput.setText(newValue); - } - }); - playStartOffsetInput.setText( - parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY_START_OFFSET)); - actionCenterPanel.add(playStartOffsetLabel); - actionCenterPanel.add(playStartOffsetInput); - - JLabel playEndOffsetLabel = new JLabel("End Offset: "); - playEndOffsetInput = new JTextField(4); - playEndOffsetInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - String newValue = playEndOffsetInput.getText(); - newValue = parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY_END_OFFSET, - newValue); - playEndOffsetInput.setText(newValue); - } - }); - playEndOffsetInput - .setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY_END_OFFSET)); - actionCenterPanel.add(playEndOffsetLabel); - actionCenterPanel.add(playEndOffsetInput); - - JLabel persistenceModeLabel = new JLabel("Persistence Mode: "); - persistenceModeInput = new JTextField(4); - persistenceModeInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - String newValue = persistenceModeInput.getText(); - newValue = parameterManager - .setParameter(InstrumentParameterNames.PERCEPTION_HEARING_TONEMAP_PERSISTENCE_MODE, newValue); - persistenceModeInput.setText(newValue); - if (toneMapViewComboBox != null) { - if (parameterManager.getIntParameter( - InstrumentParameterNames.PERCEPTION_HEARING_TONEMAP_PERSISTENCE_MODE) <= 2) { - toneMapViewComboBox.removeAllItems(); - Arrays.asList(toneMapViewTypesMode2).stream() - .forEach(entry -> toneMapViewComboBox.addItem(entry)); - } else { - toneMapViewComboBox.removeAllItems(); - Arrays.asList(toneMapViewTypesMode3).stream() - .forEach(entry -> toneMapViewComboBox.addItem(entry)); - } - } - } - }); - persistenceModeInput.setText( - parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_TONEMAP_PERSISTENCE_MODE)); - actionEastPanel.add(persistenceModeLabel); - actionEastPanel.add(persistenceModeInput); - - panel.add(actionPanel, BorderLayout.NORTH); - - fftWindowSizeComboBox = new JComboBox<>(fftWindowSizes); - fftWindowSizeComboBox.addActionListener(new ActionListener() { - private Integer fftsize; - - @Override - public void actionPerformed(ActionEvent e) { - @SuppressWarnings("unchecked") - Integer value = (Integer) ((JComboBox) e.getSource()).getSelectedItem(); - fftsize = value; - parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_DEFAULT_WINDOW, - Integer.toString(fftsize)); - } - }); - - fftWindowSizeComboBox.setSelectedIndex(2); - instrumentPanel.add(new JLabel("FFT Window: ")); - instrumentPanel.add(fftWindowSizeComboBox); - - inputSampleRateCombobox = new JComboBox<>(inputSampleRate); - inputSampleRateCombobox.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - @SuppressWarnings("unchecked") - Integer value = (Integer) ((JComboBox) e.getSource()).getSelectedItem(); - Integer sampleRate = value; - parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_DEFAULT_SAMPLE_RATE, - Integer.toString(sampleRate)); - } - }); - inputSampleRateCombobox.setSelectedIndex(3); - instrumentPanel.add(new JLabel("Sample rate: ")); - instrumentPanel.add(inputSampleRateCombobox); - - JLabel audioFeatureIntervalLabel = new JLabel("Interval: "); - audioFeatureIntervalInput = new JTextField(3); - audioFeatureIntervalInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JTextField textField = (JTextField) e.getSource(); - String newValue = textField.getText(); - newValue = parameterManager - .setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_FEATURE_INTERVAL, newValue); - textField.setText(newValue); - } - }); - - resampleSwitchCB = new JCheckBox("resampleSwitchCB"); - resampleSwitchCB.setText("ReS"); - resampleSwitchCB.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - JCheckBox cb = (JCheckBox) e.getSource(); - boolean newValue = cb.isSelected(); - parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_RESAMPLE, - Boolean.toString(newValue)); - } - }); - - resampleSwitchCB.setSelected( - parameterManager.getBooleanParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_RESAMPLE)); - instrumentPanel.add(resampleSwitchCB); - - audioFeatureIntervalInput.setText( - parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_FEATURE_INTERVAL)); - instrumentPanel.add(audioFeatureIntervalLabel); - instrumentPanel.add(audioFeatureIntervalInput); - - JLabel audioOffsetLabel = new JLabel("Offset: "); - audioOffsetInput = new JTextField(4); - audioOffsetInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JTextField textField = (JTextField) e.getSource(); - String newValue = textField.getText(); - newValue = parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_OFFSET, - newValue); - textField.setText(newValue); - } - }); - - audioOffsetInput - .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_OFFSET)); - instrumentPanel.add(audioOffsetLabel); - instrumentPanel.add(audioOffsetInput); - - audioFeatureIntervalInput.setText( - parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_FEATURE_INTERVAL)); - instrumentPanel.add(audioFeatureIntervalLabel); - instrumentPanel.add(audioFeatureIntervalInput); - - JLabel audioGainLabel = new JLabel("Gain: "); - audioGainInput = new JTextField(3); - audioGainInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JTextField textField = (JTextField) e.getSource(); - String newValue = textField.getText(); - newValue = parameterManager - .setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_GAIN_COMPRESS_FACTOR, newValue); - textField.setText(newValue); - } - }); - - audioGainInput.setText( - parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_GAIN_COMPRESS_FACTOR)); - instrumentPanel.add(audioGainLabel); - instrumentPanel.add(audioGainInput); - - JLabel audioTimeStretchLabel = new JLabel("Stretch: "); - audioTimeStretchInput = new JTextField(3); - audioTimeStretchInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JTextField textField = (JTextField) e.getSource(); - String newValue = textField.getText(); - newValue = parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_TIME_STRETCH, - newValue); - textField.setText(newValue); - } - }); - - audioTimeStretchInput - .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_TIME_STRETCH)); - instrumentPanel.add(audioTimeStretchLabel); - instrumentPanel.add(audioTimeStretchInput); - - JLabel audioPitchShiftLabel = new JLabel("Shift: "); - audioPitchShiftInput = new JTextField(3); - audioPitchShiftInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JTextField textField = (JTextField) e.getSource(); - String newValue = textField.getText(); - newValue = parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_PITCH_SHIFT, - newValue); - textField.setText(newValue); - } - }); - - audioPitchShiftInput - .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_PITCH_SHIFT)); - instrumentPanel.add(audioPitchShiftLabel); - instrumentPanel.add(audioPitchShiftInput); - - JLabel audioRangeLabel = new JLabel("Range: "); - audioRangeInput = new JTextField(4); - audioRangeInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JTextField textField = (JTextField) e.getSource(); - String newValue = textField.getText(); - newValue = parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_RANGE, - newValue); - textField.setText(newValue); - } - }); - - audioRangeInput.setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_RANGE)); - instrumentPanel.add(audioRangeLabel); - instrumentPanel.add(audioRangeInput); - - JLabel padBeforeLabel = new JLabel("Pad Before: "); - padBeforeInput = new JTextField(3); - padBeforeInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JTextField textField = (JTextField) e.getSource(); - String newValue = textField.getText(); - newValue = parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_PAD_BEFORE, - newValue); - textField.setText(newValue); - } - }); - - padBeforeInput - .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_PAD_BEFORE)); - instrumentPanel.add(padBeforeLabel); - instrumentPanel.add(padBeforeInput); - - JLabel padAfterLabel = new JLabel("After: "); - padAfterInput = new JTextField(3); - padAfterInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JTextField textField = (JTextField) e.getSource(); - String newValue = textField.getText(); - newValue = parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_PAD_AFTER, - newValue); - textField.setText(newValue); - } - }); - - padAfterInput - .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_PAD_AFTER)); - instrumentPanel.add(padAfterLabel); - instrumentPanel.add(padAfterInput); - - JLabel hearingMinFreqCentsLabel = new JLabel("Cents Min: "); - hearingMinFreqCentsInput = new JTextField(3); - hearingMinFreqCentsInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - String newValue = hearingMinFreqCentsInput.getText(); - newValue = parameterManager - .setParameter(InstrumentParameterNames.PERCEPTION_HEARING_MINIMUM_FREQUENCY_CENTS, newValue); - hearingMinFreqCentsInput.setText(newValue); - } - }); - hearingMinFreqCentsInput.setText( - parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_MINIMUM_FREQUENCY_CENTS)); - instrumentPanel.add(hearingMinFreqCentsLabel); - instrumentPanel.add(hearingMinFreqCentsInput); - - JLabel hearingMaxFreqCentsLabel = new JLabel("Max: "); - hearingMaxFreqCentsInput = new JTextField(3); - hearingMaxFreqCentsInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - String newValue = hearingMaxFreqCentsInput.getText(); - newValue = parameterManager - .setParameter(InstrumentParameterNames.PERCEPTION_HEARING_MAXIMUM_FREQUENCY_CENTS, newValue); - hearingMaxFreqCentsInput.setText(newValue); - } - }); - hearingMaxFreqCentsInput.setText( - parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_MAXIMUM_FREQUENCY_CENTS)); - instrumentPanel.add(hearingMaxFreqCentsLabel); - instrumentPanel.add(hearingMaxFreqCentsInput); - - JLabel searchLabel = new JLabel("Search: "); - searchCountInput = new JTextField(3); - searchCountInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - String newValue = searchCountInput.getText(); - newValue = parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AI_SEARCH_COUNT, - newValue); - searchCountInput.setText(newValue); - } - }); - searchCountInput - .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AI_SEARCH_COUNT)); - instrumentPanel.add(searchLabel); - instrumentPanel.add(searchCountInput); - - panel.add(instrumentPanel, BorderLayout.CENTER); - - playMidiSwitchCB = new JCheckBox("playMidiSwitchCB"); - playMidiSwitchCB.setText("MIDI"); - playMidiSwitchCB.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - JCheckBox cb = (JCheckBox) e.getSource(); - boolean newValue = cb.isSelected(); - parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY, - Boolean.toString(newValue)); - } - }); - - playMidiSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY)); - voicePanel.add(playMidiSwitchCB); - - playMidiDeviceSwitchCB = new JCheckBox("playMidiDeviceSwitchCB"); - playMidiDeviceSwitchCB.setText("Device"); - playMidiDeviceSwitchCB.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - JCheckBox cb = (JCheckBox) e.getSource(); - boolean newValue = cb.isSelected(); - parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_DEVICE_PLAY_SWITCH, - Boolean.toString(newValue)); - } - }); - - playMidiDeviceSwitchCB.setSelected( - parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_DEVICE_PLAY_SWITCH)); - voicePanel.add(playMidiDeviceSwitchCB); - - playAudioSwitchCB = new JCheckBox("playAudioSwitchCB"); - playAudioSwitchCB.setText("Audio"); - playAudioSwitchCB.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - JCheckBox cb = (JCheckBox) e.getSource(); - boolean newValue = cb.isSelected(); - parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_AUDIO_PLAY, - Boolean.toString(newValue)); - } - }); - - playAudioSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_AUDIO_PLAY)); - voicePanel.add(playAudioSwitchCB); - - playResynthSwitchCB = new JCheckBox("playResynthSwitchCB"); - playResynthSwitchCB.setText("Resynth"); - playResynthSwitchCB.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - JCheckBox cb = (JCheckBox) e.getSource(); - boolean newValue = cb.isSelected(); - parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_RESYNTH_PLAY, - Boolean.toString(newValue)); - } - }); - - playResynthSwitchCB.setSelected( - parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_RESYNTH_PLAY)); - voicePanel.add(playResynthSwitchCB); - - playPeaksSwitchCB = new JCheckBox("playPeaksSwitchCB"); - playPeaksSwitchCB.setText("PEAKS"); - playPeaksSwitchCB.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - JCheckBox cb = (JCheckBox) e.getSource(); - boolean newValue = cb.isSelected(); - parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_PLAY_PEAKS, - Boolean.toString(newValue)); - } - }); - - playPeaksSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_PLAY_PEAKS)); - voicePanel.add(playPeaksSwitchCB); - - pausePlaySwitchCB = new JCheckBox("pausePlaySwitchCB"); - pausePlaySwitchCB.setText("Pause"); - pausePlaySwitchCB.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - JCheckBox cb = (JCheckBox) e.getSource(); - boolean newValue = cb.isSelected(); - parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_PAUSE_PLAY_SWITCH, - Boolean.toString(newValue)); - } - }); - - pausePlaySwitchCB.setSelected( - parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_PAUSE_PLAY_SWITCH)); - voicePanel.add(pausePlaySwitchCB); - - JLabel spacer1Label = new JLabel(" "); - voicePanel.add(spacer1Label); - - JLabel voicePlayerDelayLabel = new JLabel("Delay: "); - voicePlayerDelayInput = new JTextField(4); - voicePlayerDelayInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - String newValue = voicePlayerDelayInput.getText(); - newValue = parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_DELAY, newValue); - voicePlayerDelayInput.setText(newValue); - } - }); - - voicePlayerDelayInput.setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_DELAY)); - voicePanel.add(voicePlayerDelayLabel); - voicePanel.add(voicePlayerDelayInput); - - JLabel voicePlayerRepeatLabel = new JLabel("Repeat: "); - voicePlayerRepeatInput = new JTextField(4); - voicePlayerRepeatInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - String newValue = voicePlayerRepeatInput.getText(); - newValue = parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_PLAY_REPEAT, - newValue); - voicePlayerRepeatInput.setText(newValue); - } - }); - - voicePlayerRepeatInput - .setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_PLAY_REPEAT)); - voicePanel.add(voicePlayerRepeatLabel); - voicePanel.add(voicePlayerRepeatInput); - - loopSaveSwitchCB = new JCheckBox("loopSaveSwitchCB"); - loopSaveSwitchCB.setText("Loops"); - loopSaveSwitchCB.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - JCheckBox cb = (JCheckBox) e.getSource(); - boolean newValue = cb.isSelected(); - parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_LOOP_SAVE, - Boolean.toString(newValue)); - } - }); - - loopSaveSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_LOOP_SAVE)); - voicePanel.add(loopSaveSwitchCB); - - JLabel voicePlayerLowThresholdLabel = new JLabel("Low Threshold: "); - voicePlayerLowThresholdInput = new JTextField(4); - voicePlayerLowThresholdInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JTextField textField = (JTextField) e.getSource(); - String newValue = textField.getText(); - newValue = parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_LOW_THRESHOLD, - newValue); - voicePlayerLowThresholdInput.setText(newValue); - } - }); - - voicePlayerLowThresholdInput - .setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_LOW_THRESHOLD)); - voicePanel.add(voicePlayerLowThresholdLabel); - voicePanel.add(voicePlayerLowThresholdInput); - - JLabel voicePlayerHighThresholdLabel = new JLabel("High Threshold: "); - voicePlayerHighThresholdInput = new JTextField(4); - voicePlayerHighThresholdInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JTextField textField = (JTextField) e.getSource(); - String newValue = textField.getText(); - newValue = parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_HIGH_THRESHOLD, - newValue); - voicePlayerHighThresholdInput.setText(newValue); - } - }); - - voicePlayerHighThresholdInput - .setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_HIGH_THRESHOLD)); - voicePanel.add(voicePlayerHighThresholdLabel); - voicePanel.add(voicePlayerHighThresholdInput); - - midiPlayVolumeSwitchCB = new JCheckBox("midiPlayVolumeSwitchCB"); - midiPlayVolumeSwitchCB.setText("Volume"); - midiPlayVolumeSwitchCB.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - JCheckBox cb = (JCheckBox) e.getSource(); - boolean newValue = cb.isSelected(); - parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY_VOLUME_SWITCH, - Boolean.toString(newValue)); - } - }); - - midiPlayVolumeSwitchCB.setSelected( - parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY_VOLUME_SWITCH)); - voicePanel.add(midiPlayVolumeSwitchCB); - - midiPlayLogSwitchCB = new JCheckBox("midiPlayLogSwitchCB"); - midiPlayLogSwitchCB.setText("Log"); - midiPlayLogSwitchCB.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - JCheckBox cb = (JCheckBox) e.getSource(); - boolean newValue = cb.isSelected(); - parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY_LOG_SWITCH, - Boolean.toString(newValue)); - } - }); - - midiPlayLogSwitchCB.setSelected( - parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY_LOG_SWITCH)); - voicePanel.add(midiPlayLogSwitchCB); - - JLabel voicePlayerLogFactorLabel = new JLabel("Log Factor: "); - voicePlayerLogFactorInput = new JTextField(4); - voicePlayerLogFactorInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JTextField textField = (JTextField) e.getSource(); - String newValue = textField.getText(); - newValue = parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_LOG_FACTOR, newValue); - voicePlayerLogFactorInput.setText(newValue); - } - }); - - voicePlayerLogFactorInput - .setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_LOG_FACTOR)); - voicePanel.add(voicePlayerLogFactorLabel); - voicePanel.add(voicePlayerLogFactorInput); - - JLabel voicePlayerGlissandoRangeLabel = new JLabel("Glissando: "); - voicePlayerGlissandoRangeInput = new JTextField(4); - voicePlayerGlissandoRangeInput.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JTextField textField = (JTextField) e.getSource(); - String newValue = textField.getText(); - newValue = parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_GLISSANDO_RANGE, - newValue); - voicePlayerGlissandoRangeInput.setText(newValue); - } - }); - - voicePlayerGlissandoRangeInput - .setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_GLISSANDO_RANGE)); - voicePanel.add(voicePlayerGlissandoRangeLabel); - voicePanel.add(voicePlayerGlissandoRangeInput); - - voicePanel.add(new JLabel(" ")); - - midiSynthTracksSwitchCB = new JCheckBox("midiSynthTracksSwitchCB"); - midiSynthTracksSwitchCB.setText("Synth"); - midiSynthTracksSwitchCB.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - JCheckBox cb = (JCheckBox) e.getSource(); - boolean newValue = cb.isSelected(); - parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_SYNTH_TRACKS_SWITCH, - Boolean.toString(newValue)); - } - }); - - midiSynthTracksSwitchCB.setSelected(parameterManager - .getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_SYNTH_TRACKS_SWITCH)); - voicePanel.add(midiSynthTracksSwitchCB); - - silentWriteSwitchCB = new JCheckBox("silentWriteCB"); - silentWriteSwitchCB.setText("Silent Write"); - silentWriteSwitchCB.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - JCheckBox cb = (JCheckBox) e.getSource(); - boolean newValue = cb.isSelected(); - parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_SILENT_WRITE, - Boolean.toString(newValue)); - } - }); - - silentWriteSwitchCB.setSelected( - parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_SILENT_WRITE)); - voicePanel.add(silentWriteSwitchCB); - - trackWriteSwitchCB = new JCheckBox("trackWriteCB"); - trackWriteSwitchCB.setText("Track Write"); - trackWriteSwitchCB.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - JCheckBox cb = (JCheckBox) e.getSource(); - boolean newValue = cb.isSelected(); - parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_TRACK_WRITE_SWITCH, - Boolean.toString(newValue)); - } - }); - - trackWriteSwitchCB.setSelected( - parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_TRACK_WRITE_SWITCH)); - voicePanel.add(trackWriteSwitchCB); - - recordSwitchCB = new JCheckBox("recordSwitchCB"); - recordSwitchCB.setText("Record"); - recordSwitchCB.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - JCheckBox cb = (JCheckBox) e.getSource(); - boolean newValue = cb.isSelected(); - parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_RECORD_SWITCH, - Boolean.toString(newValue)); - } - }); - - recordSwitchCB.setSelected( - parameterManager.getBooleanParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_RECORD_SWITCH)); - voicePanel.add(recordSwitchCB); - - panel.add(voicePanel, BorderLayout.SOUTH); - - return panel; - } - - private String getAudioSourceFileFolder() { - return parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_SOURCE_DIRECTORY); - } - - private String getDefaultAudioFile() { - return parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_DEFAULT_FILE); - } - - private String getAudioRecordFileFolder() { - String baseDir = storage.getObjectStorage().getBasePath(); - return Paths - .get(baseDir, - parameterManager - .getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_RECORD_DIRECTORY)) - .toString(); - } - - @Override - public void audioFeatureFrameAdded(AudioFeatureFrame audioFeatureFrame) { - updateView(audioFeatureFrame); - } - - @Override - public void audioFeatureFrameChanged(AudioFeatureFrame audioFeatureFrame) { - updateView(audioFeatureFrame); - } - - @Override - public void clearView() { - toneMapViews.clear(); - cqLayer.clear(); - pdLayer.clear(); - this.cqPanel.repaint(); - this.pitchDetectPanel.repaint(); - this.frameNumberInput.setText("0"); - } - - @Override - public void showFrame(int frame) { - if (frame > 0) { - if (toneMapViews.containsKey(currentToneMapViewType)) { - ToneMap currentToneMap = toneMapViews.get(currentToneMapViewType); - ToneTimeFrame toneTimeFrame = currentToneMap.getTimeFrame(frame); - if (toneTimeFrame != null) { - updateTimeFrameView(toneTimeFrame); - int timeOffset = (int) (toneTimeFrame.getStartTime() * 1000.0); - parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_OFFSET, - Integer.toString(timeOffset)); - timeAxisOffsetInput.setText(Integer.toString(timeOffset)); - refreshMapViews(); - updateSpectrumView(toneTimeFrame, parameterManager - .getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_DEFAULT_WINDOW)); - } - } - } - } - - @Override - public void updateTimeFrameView(ToneTimeFrame data) { - timeFramePanel.paint(data); - timeFramePanel.repaint(); - } - - @Override - @SuppressWarnings("unchecked") - public void updateToneMapView(ToneMap toneMap, String toneMapViewType) { - - List timeFrames = new ArrayList<>(); - ToneTimeFrame ttf = toneMap.getTimeFrame(); - if (ttf != null) { - double fromTime = (ttf.getStartTime() - 1.0) >= 0 ? ttf.getStartTime() - 1.0 : 0; - - while (ttf != null && ttf.getStartTime() >= fromTime) { - timeFrames.add(ttf); - ttf = toneMap.getPreviousTimeFrame(ttf.getStartTime()); - } - for (ToneTimeFrame ttfv : timeFrames) { - updateToneMapView(toneMap, ttfv, toneMapViewType); - } - } - } - - @Override - @SuppressWarnings("unchecked") - public void updateToneMapView(ToneMap toneMap, ToneTimeFrame ttf, String toneMapViewType) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - if (!toneMapViews.containsKey(toneMapViewType)) { - toneMapViews.put(toneMapViewType, toneMap); - if (toneMapViewType.equals(currentToneMapViewType)) { - toneMapView.renderToneMap(toneMap); - beatsView.renderToneMap(toneMap); - chromaView.renderToneMap(toneMap); - } - } else if (toneMapView.getToneMap() != null && toneMapViews.get(toneMapViewType) != null - && !toneMapViews.get(toneMapViewType).getKey().equals(toneMapView.getToneMap().getKey())) { - toneMapViews.put(toneMapViewType, toneMap); - if (toneMapViewType.equals(currentToneMapViewType)) { - toneMapView.renderToneMap(toneMap); - beatsView.renderToneMap(toneMap); - chromaView.renderToneMap(toneMap); - } - } else if (toneMapViewType.equals(currentToneMapViewType) && toneMapView != null) { - toneMapView.updateToneMap(toneMap, ttf); - beatsView.updateToneMap(toneMap, ttf); - chromaView.updateToneMap(toneMap, ttf); - } - updateTimeFrameView(ttf); - } - }); - } - - private void switchToneMapView() { - if (toneMapViews.containsKey(currentToneMapViewType)) { - toneMapView.renderToneMap(toneMapViews.get(currentToneMapViewType)); - updateTimeFrameView(toneMapViews.get(currentToneMapViewType).getTimeFrame()); - } - } - - private void resetToneMapView() { - if (toneMapViews.containsKey(currentToneMapViewType)) { - toneMapView.renderToneMap(toneMapViews.get(currentToneMapViewType)); - updateTimeFrameView(toneMapViews.get(currentToneMapViewType).getTimeFrame()); - chromaView.renderToneMap(toneMapViews.get(currentToneMapViewType)); - beatsView.renderToneMap(toneMapViews.get(currentToneMapViewType)); - } else { - toneMapView.clear(); - chromaView.clear(); - beatsView.clear(); - } - } - - @Override - public void updateSpectrumView(ToneTimeFrame toneTimeFrame, int windowSize) { - if (toneTimeFrame != null) { - float[] spectrum = toneTimeFrame.extractFFTSpectrum(windowSize).getSpectrum(); - for (int i = 0; i < spectrum.length; i++) { - spectrum[i] *= 100; - } - spectrumLayer.clearPeaks(); - spectrumLayer.setSpectrum(spectrum); - spectrumPanel.repaint(); - } - } - - private LinkedPanel createCQPanel() { - CoordinateSystem constantQCS = getCoordinateSystem(AxisUnit.FREQUENCY); - constantQCS.setMax(Axis.X, 20000); - constantQPanel = new LinkedPanel(constantQCS); - cqLayer = new CQLayer(constantQCS); - constantQPanel.addLayer(new BackgroundLayer(constantQCS)); - constantQPanel.addLayer(cqLayer); - constantQPanel.addLayer(new VerticalFrequencyAxisLayer(constantQCS)); - constantQPanel.addLayer(new ZoomMouseListenerLayer()); - constantQPanel.addLayer(new DragMouseListenerLayer(constantQCS)); - constantQPanel.addLayer(new SelectionLayer(constantQCS)); - constantQPanel.addLayer(new TimeAxisLayer(constantQCS)); - - LegendLayer legend = new LegendLayer(constantQCS, 110); - constantQPanel.addLayer(legend); - legend.addEntry("ConstantQ", Color.BLACK); - legend.addEntry("Pitch estimations", Color.RED); - ViewPortChangedListener listener = new ViewPortChangedListener() { - @Override - public void viewPortChanged(ViewPort newViewPort) { - constantQPanel.repaint(); - } - }; - constantQPanel.getViewPort().addViewPortChangedListener(listener); - return constantQPanel; - } - - private LinkedPanel createPitchDetectPanel() { - CoordinateSystem cs = getCoordinateSystem(AxisUnit.FREQUENCY); - cs.setMax(Axis.X, 20000); - pitchDetectPanel = new LinkedPanel(cs); - pitchDetectPanel.addLayer(new BackgroundLayer(cs)); - pdLayer = new PitchDetectLayer(cs); - pitchDetectPanel.addLayer(pdLayer); - pitchDetectPanel.addLayer(new VerticalFrequencyAxisLayer(cs)); - pitchDetectPanel.addLayer(new ZoomMouseListenerLayer()); - pitchDetectPanel.addLayer(new DragMouseListenerLayer(cs)); - pitchDetectPanel.addLayer(new SelectionLayer(cs)); - pitchDetectPanel.addLayer(new TimeAxisLayer(cs)); - - LegendLayer legend = new LegendLayer(cs, 110); - pitchDetectPanel.addLayer(legend); - legend.addEntry("Pitch", Color.BLACK); - ViewPortChangedListener listener = new ViewPortChangedListener() { - @Override - public void viewPortChanged(ViewPort newViewPort) { - pitchDetectPanel.repaint(); - } - }; - pitchDetectPanel.getViewPort().addViewPortChangedListener(listener); - return pitchDetectPanel; - } - - private LinkedPanel createSpectrumPanel() { - CoordinateSystem cs = new CoordinateSystem(AxisUnit.FREQUENCY, AxisUnit.AMPLITUDE, 0, 1000, false); - cs.setMax(Axis.X, 4800); - cs.setMax(Axis.X, 13200); - spectrumLayer = new SpectrumLayer(cs, - parameterManager.getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_DEFAULT_WINDOW), - parameterManager.getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_DEFAULT_SAMPLE_RATE), - Color.black); - // noiseFloorLayer = new SpectrumLayer(cs, - // parameterManager.getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_SP_WINDOW), - // parameterManager.getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_DEFAULT_SAMPLE_RATE), - // Color.gray); - - spectrumPanel = new LinkedPanel(cs); - spectrumPanel.addLayer(new ZoomMouseListenerLayer()); - spectrumPanel.addLayer(new DragMouseListenerLayer(cs)); - spectrumPanel.addLayer(new BackgroundLayer(cs)); - spectrumPanel.addLayer(new AmplitudeAxisLayer(cs)); - - spectrumPanel.addLayer(new SelectionLayer(cs)); - spectrumPanel.addLayer(new HorizontalFrequencyAxisLayer(cs)); - spectrumPanel.addLayer(spectrumLayer); - // spectrumPanel.addLayer(noiseFloorLayer); - - spectrumPanel.getViewPort().addViewPortChangedListener(new ViewPortChangedListener() { - boolean painting = false; - - @Override - public void viewPortChanged(ViewPort newViewPort) { - if (!painting) { - painting = true; - spectrumPanel.repaint(); - painting = false; - } - } - }); - return spectrumPanel; - } - - private JPanel createToneMapLayerPanel() { - toneMapView = new ToneMapView(); - JPanel tmContainer = new JPanel(new BorderLayout()); - tmContainer.add(toneMapView, BorderLayout.CENTER); - tmContainer.setBackground(Color.BLACK); - return tmContainer; - } - - private CoordinateSystem getCoordinateSystem(AxisUnit yUnits) { - float minValue = -1000; - float maxValue = 1000; - if (yUnits == AxisUnit.FREQUENCY) { - minValue = 400; - maxValue = 12000; - } - return new CoordinateSystem(yUnits, minValue, maxValue); - } - - private void updateView(AudioFeatureFrame audioFeatureFrame) { - cqLayer.update(audioFeatureFrame); - pdLayer.update(audioFeatureFrame); - cqPanel.repaint(); - pitchDetectPanel.repaint(); - this.frameNumberInput.setText(Integer.toString(audioFeatureFrame.getFrameSequence())); - } - - @Override - public void audioStopped() { - startFileProcessingButton.setEnabled(true); - startListeningButton.setEnabled(true); - // stopListeningButton.setEnabled(false); - chooseFileButton.setEnabled(true); - frameNumberInput.setEnabled(true); - } - - private static class CQLayer implements Layer { - - private float binHeight; - private float[] binStartingPointsInCents; - - private float binWidth; - private TreeMap cqFeatures; - private final CoordinateSystem cs; - - public CQLayer(CoordinateSystem cs) { - this.cs = cs; - } - - @Override - public void draw(Graphics2D graphics) { - - if (cqFeatures != null) { - Map spectralInfoSubMap = cqFeatures.subMap(cs.getMin(Axis.X) / 1000.0, - cs.getMax(Axis.X) / 1000.0); - float minValue = 5 / 1000000.0F; - float currentMaxSpectralEnergy = 0; - for (Map.Entry column : spectralInfoSubMap.entrySet()) { - float[] spectralEnergy = column.getValue(); - for (float element : spectralEnergy) { - float magnitude = Math.max(minValue, element); - magnitude = (float) Math.log10(1 + (100.0 * magnitude)); - currentMaxSpectralEnergy = Math.max(currentMaxSpectralEnergy, magnitude); - } - } - for (Map.Entry column : spectralInfoSubMap.entrySet()) { - double timeStart = column.getKey();// in seconds - float[] spectralEnergy = column.getValue();// in cents - // draw the pixels - for (int i = 0; i < spectralEnergy.length; i++) { - Color color = Color.black; - float centsStartingPoint = binStartingPointsInCents[i]; - // only draw the visible frequency range - if (centsStartingPoint >= cs.getMin(Axis.Y) && centsStartingPoint <= cs.getMax(Axis.Y)) { - // int greyValue = 255 - (int) - // (Math.log1p(spectralEnergy[i]) - // / Math.log1p(currentMaxSpectralEnergy) * 255); - float magnitude = Math.max(minValue, spectralEnergy[i]); - magnitude = (float) Math.log10(1 + (100.0 * magnitude)); - int greyValue = 255 - (int) (magnitude / (currentMaxSpectralEnergy) * 255); - greyValue = Math.max(0, greyValue); - color = new Color(greyValue, greyValue, greyValue); - graphics.setColor(color); - graphics.fillRect((int) Math.round(timeStart * 1000), Math.round(centsStartingPoint), - Math.round(binWidth * 1000), (int) Math.ceil(binHeight)); - } - } - } - } - } - - public void clear() { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - cqFeatures = new TreeMap<>(); - } - }); - } - - @Override - public String getName() { - return "CQ Layer"; - } - - public void update(AudioFeatureFrame audioFeatureFrame) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - ConstantQSource cqs = audioFeatureFrame.getConstantQFeatures().getSource(); - binStartingPointsInCents = cqs.getBinStartingPointsInCents(); - binWidth = cqs.getBinWidth(); - binHeight = cqs.getBinHeight(); - Map fs = audioFeatureFrame.getConstantQFeatures().getFeatures(); - if (cqFeatures == null) { - cqFeatures = new TreeMap<>(); - } - for (java.util.Map.Entry entry : fs.entrySet()) { - cqFeatures.put(entry.getKey(), entry.getValue()); - } - } - }); - } - } - - private static class TimeFramePanel extends JPanel { - - private ToneTimeFrame toneTimeFrame; - - public TimeFramePanel() { - setMinimumSize(new Dimension(80, 60)); - } - - public void paint(ToneTimeFrame toneTimeFrame) { - this.toneTimeFrame = toneTimeFrame; - } - - @Override - public void paintComponent(Graphics g) { - super.paintComponent(g); // paint background - g.setColor(Color.BLACK); - g.fillRect(0, 0, getWidth(), getHeight()); - g.setColor(Color.WHITE); - if (toneTimeFrame != null) { - float width = getWidth(); - float height = getHeight(); - ToneMapElement[] elements = toneTimeFrame.getElements(); - double xInc = width / elements.length; - double yInc = height / 1.0; - int x = 0; - int y = 0; - for (int i = 0; i < elements.length; i++) { - ToneMapElement element = elements[i]; - x = (int) (i * xInc); - y = (int) height - 1; - if ((toneTimeFrame.getMaxAmplitude() - toneTimeFrame.getMinAmplitude()) > 0.1) { - y = (int) (height - (yInc * ((element.amplitude - toneTimeFrame.getMinAmplitude()) - / (toneTimeFrame.getMaxAmplitude() - toneTimeFrame.getMinAmplitude())))); - } - g.drawLine(x, (int) height - 1, x, y); - } - } - } - } - - private static class PitchDetectLayer implements Layer { - - private float binHeight; - private float[] binStartingPointsInCents; - private float binWidth; - private final CoordinateSystem cs; - TreeMap features; - - public PitchDetectLayer(CoordinateSystem cs) { - this.cs = cs; - } - - @Override - public void draw(Graphics2D graphics) { - - if (features != null) { - - Map spSubMap = features.subMap(cs.getMin(Axis.X) / 1000.0, - cs.getMax(Axis.X) / 1000.0); - double maxAmp = 0.00001; - for (Entry column : spSubMap.entrySet()) { - - double timeStart = column.getKey();// in seconds - SpectrogramInfo spectrogramInfo = column.getValue();// in - // cents - float pitch = spectrogramInfo.getPitchDetectionResult().getPitch(); // -1? - float[] amplitudes = spectrogramInfo.getAmplitudes(); - // draw the pixels - for (int i = 0; i < amplitudes.length; i++) { - Color color = Color.black; - float centsStartingPoint = binStartingPointsInCents[i]; - // only draw the visible frequency range - if (centsStartingPoint >= cs.getMin(Axis.Y) && centsStartingPoint <= cs.getMax(Axis.Y)) { - // int greyValue = 255 - (int) - // (Math.log1p(spectralEnergy[i]) - // / Math.log1p(currentMaxSpectralEnergy) * 255); - if (amplitudes[i] > maxAmp) { - maxAmp = amplitudes[i]; - } - int greyValue = 255 - (int) (amplitudes[i] / (maxAmp) * 255); - greyValue = Math.max(0, greyValue); - color = new Color(greyValue, greyValue, greyValue); - graphics.setColor(color); - graphics.fillRect((int) Math.round(timeStart * 1000), Math.round(centsStartingPoint), - Math.round(binWidth * 1000), (int) Math.ceil(binHeight)); - - } - } - - if (pitch > -1) { - double cents = PitchConverter.hertzToAbsoluteCent(pitch); - Color color = Color.red; - // only draw the visible frequency range - if (cents >= cs.getMin(Axis.Y) && cents <= cs.getMax(Axis.Y)) { - // int greyValue = (int) (255F * probability); - // greyValue = Math.max(0, greyValue); - // color = new Color(greyValue, greyValue, - // greyValue); - graphics.setColor(color); - graphics.fillRect((int) Math.round(timeStart * 1000), (int) cents, Math.round(40), - (int) Math.ceil(100)); - } - } - } - } - } - - @Override - public String getName() { - return "Pitch Detect Layer"; - } - - public void clear() { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - features = new TreeMap<>(); - } - }); - } - - public void update(AudioFeatureFrame audioFeatureFrame) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - TreeMap fs; - PitchDetectorSource pds; - pds = audioFeatureFrame.getPitchDetectorFeatures().getSource(); - binStartingPointsInCents = pds.getBinStartingPointsInCents(); - binWidth = pds.getBinWidth(); - binHeight = pds.getBinHeight(); - fs = audioFeatureFrame.getPitchDetectorFeatures().getFeatures(); - if (features == null) { - features = new TreeMap<>(); - } - for (Entry entry : fs.entrySet()) { - features.put(entry.getKey(), entry.getValue()); - } - } - }); - } - } - - private void refreshMapViews() { - if (toneMapView != null) { - toneMapView.updateAxis(); - chromaView.updateAxis(); - beatsView.updateAxis(); - } - } - - protected void repaintSpectralInfo(AudioFeatureFrame audioFeatureFrame) { - TreeMap fs; - SpectralPeaksSource sps = audioFeatureFrame.getSpectralPeaksFeatures().getSource(); - fs = audioFeatureFrame.getSpectralPeaksFeatures().getFeatures(); - spectrumLayer.clearPeaks(); - for (Entry entry : fs.entrySet()) { - spectrumLayer.setSpectrum(entry.getValue().getMagnitudes()); - spectrumPanel.repaint(); - } - } - - @Override - public void updateParameters() { - timeAxisOffsetInput - .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_OFFSET)); - pitchAxisOffsetInput - .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_VIEW_PITCH_AXIS_OFFSET)); - timeAxisRangeInput - .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_RANGE)); - pitchAxisRangeInput - .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_VIEW_PITCH_AXIS_RANGE)); - showColourSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_COLOUR)); - showPeaksSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_PEAKS)); - showPowerSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_POWER)); - showNotesSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_NOTES)); - showChordsSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_CHORDS)); - showBaseSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_BASE)); - showBeatsSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_BEATS)); - showStatsSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_STATS)); - showLogSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_LOG)); - toneMapViewLowThresholdInput - .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_TONEMAP_VIEW_LOW_THRESHOLD)); - toneMapViewHighThresholdInput - .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_TONEMAP_VIEW_HIGH_THRESHOLD)); - recordSwitchCB.setSelected( - parameterManager.getBooleanParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_RECORD_SWITCH)); - audioFeatureIntervalInput.setText( - parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_FEATURE_INTERVAL)); - audioOffsetInput - .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_OFFSET)); - audioGainInput.setText( - parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_GAIN_COMPRESS_FACTOR)); - audioTimeStretchInput - .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_TIME_STRETCH)); - audioRangeInput.setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_RANGE)); - audioPitchShiftInput - .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_PITCH_SHIFT)); - padBeforeInput - .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_PAD_BEFORE)); - padAfterInput - .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_PAD_AFTER)); - resampleSwitchCB.setSelected( - parameterManager.getBooleanParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_RESAMPLE)); - hearingMinFreqCentsInput.setText( - parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_MINIMUM_FREQUENCY_CENTS)); - hearingMaxFreqCentsInput.setText( - parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_MAXIMUM_FREQUENCY_CENTS)); - searchCountInput - .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AI_SEARCH_COUNT)); - persistenceModeInput.setText( - parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_TONEMAP_PERSISTENCE_MODE)); - playMidiSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY)); - playMidiDeviceSwitchCB.setSelected( - parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_DEVICE_PLAY_SWITCH)); - playAudioSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_AUDIO_PLAY)); - playResynthSwitchCB.setSelected( - parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_RESYNTH_PLAY)); - playPeaksSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_PLAY_PEAKS)); - loopSaveSwitchCB - .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_LOOP_SAVE)); - voicePlayerRepeatInput - .setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_PLAY_REPEAT)); - - pausePlaySwitchCB.setSelected( - parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_PAUSE_PLAY_SWITCH)); - voicePlayerDelayInput.setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_DELAY)); - voicePlayerLowThresholdInput - .setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_LOW_THRESHOLD)); - voicePlayerHighThresholdInput - .setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_HIGH_THRESHOLD)); - voicePlayerLogFactorInput - .setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_LOG_FACTOR)); - voicePlayerGlissandoRangeInput - .setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_GLISSANDO_RANGE)); - midiPlayLogSwitchCB.setSelected( - parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY_LOG_SWITCH)); - midiPlayVolumeSwitchCB.setSelected( - parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY_VOLUME_SWITCH)); - midiSynthTracksSwitchCB.setSelected(parameterManager - .getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_SYNTH_TRACKS_SWITCH)); - silentWriteSwitchCB.setSelected( - parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_SILENT_WRITE)); - trackWriteSwitchCB.setSelected( - parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_TRACK_WRITE_SWITCH)); - streamSaveSwitchCB.setSelected( - parameterManager.getBooleanParameter(InstrumentParameterNames.PERCEPTION_HEARING_STREAM_SAVE_SWITCH)); - cortexShortCircuitSwitchCB.setSelected( - parameterManager.getBooleanParameter(InstrumentParameterNames.PERCEPTION_CORTEX_SHORT_CIRCUIT_SWITCH)); - streamIndexInput - .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_STREAM_SAVE_INDEX)); - playStartOffsetInput.setText( - parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY_START_OFFSET)); - playEndOffsetInput - .setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY_END_OFFSET)); - int sampleRateParam = parameterManager - .getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_DEFAULT_SAMPLE_RATE); - int i = 0; - for (int sr : inputSampleRate) { - if (sr == sampleRateParam) { - inputSampleRateCombobox.setSelectedIndex(i); - break; - } - i++; - } - int fftParam = parameterManager.getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_DEFAULT_WINDOW); - i = 0; - for (int fws : fftWindowSizes) { - if (fws == fftParam) { - fftWindowSizeComboBox.setSelectedIndex(i); - break; - } - i++; - } - } - - public JPanel getContentPanel() { - return visorPanel; - } - - @Override - public void showException(InstrumentException exception) { - startListeningButton.setEnabled(false); - startFileProcessingButton.setEnabled(false); - stopListeningButton.setEnabled(false); - chooseFileButton.setEnabled(false); - frameNumberInput.setEnabled(false); - playAudioButton.setEnabled(false); - playStreamButton.setEnabled(false); - parametersButton.setEnabled(false); - updateViewButton.setEnabled(false); - synthButton.setEnabled(false); - resetSystemButton.setForeground(Color.RED); - updateStatusMessage("Instument System Error: " + exception.getMessage()); - } - - @Override - public void setPlayerState(boolean enabled) { - playStreamButton.setEnabled(enabled); - } - -} +package jomu.instrument.desktop.monitor.swing; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Container; +import java.awt.Cursor; +import java.awt.DefaultKeyboardFocusManager; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.GraphicsEnvironment; +import java.awt.GridLayout; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Toolkit; +import java.awt.Window; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; +import java.nio.file.Paths; +import java.time.LocalDateTime; +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; +import java.util.Map.Entry; +import java.util.TreeMap; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.sound.sampled.LineUnavailableException; +import javax.swing.AbstractButton; +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JDialog; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JSplitPane; +import javax.swing.JTabbedPane; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; +import javax.swing.WindowConstants; +import javax.swing.border.BevelBorder; +import javax.swing.border.CompoundBorder; +import javax.swing.border.EmptyBorder; +import javax.swing.border.EtchedBorder; + +import com.formdev.flatlaf.FlatLaf; +import com.formdev.flatlaf.intellijthemes.FlatMaterialDesignDarkIJTheme; + +import be.tarsos.dsp.ui.Axis; +import be.tarsos.dsp.ui.AxisUnit; +import be.tarsos.dsp.ui.CoordinateSystem; +import be.tarsos.dsp.ui.LinkedPanel; +import be.tarsos.dsp.ui.ViewPort; +import be.tarsos.dsp.ui.ViewPort.ViewPortChangedListener; +import be.tarsos.dsp.ui.layers.AmplitudeAxisLayer; +import be.tarsos.dsp.ui.layers.BackgroundLayer; +import be.tarsos.dsp.ui.layers.DragMouseListenerLayer; +import be.tarsos.dsp.ui.layers.HorizontalFrequencyAxisLayer; +import be.tarsos.dsp.ui.layers.Layer; +import be.tarsos.dsp.ui.layers.LegendLayer; +import be.tarsos.dsp.ui.layers.SelectionLayer; +import be.tarsos.dsp.ui.layers.TimeAxisLayer; +import be.tarsos.dsp.ui.layers.VerticalFrequencyAxisLayer; +import be.tarsos.dsp.ui.layers.ZoomMouseListenerLayer; +import be.tarsos.dsp.util.PitchConverter; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Alternative; +import jakarta.inject.Inject; +import jomu.instrument.Instrument; +import jomu.instrument.InstrumentException; +import jomu.instrument.audio.features.AudioFeatureFrame; +import jomu.instrument.audio.features.AudioFeatureFrameObserver; +import jomu.instrument.audio.features.ConstantQSource; +import jomu.instrument.audio.features.PitchDetectorSource; +import jomu.instrument.audio.features.SpectralInfo; +import jomu.instrument.audio.features.SpectralPeaksSource; +import jomu.instrument.audio.features.SpectrogramInfo; +import jomu.instrument.cognition.cell.Cell; +import jomu.instrument.control.Controller; +import jomu.instrument.control.Coordinator; +import jomu.instrument.control.InstrumentParameterNames; +import jomu.instrument.control.ParameterManager; +import jomu.instrument.monitor.Console; +import jomu.instrument.monitor.Visor; +import jomu.instrument.store.InstrumentStoreService; +import jomu.instrument.store.Storage; +import jomu.instrument.workspace.Workspace; +import jomu.instrument.workspace.tonemap.ToneMap; +import jomu.instrument.workspace.tonemap.ToneMapElement; +import jomu.instrument.workspace.tonemap.ToneTimeFrame; + +@ApplicationScoped +@Alternative +@jakarta.annotation.Priority(1) +public class SwingDesktopVisor implements Visor, AudioFeatureFrameObserver { + + private static final Logger LOG = Logger.getLogger(SwingDesktopVisor.class.getName()); + + @Inject + Instrument instrument; + + @Inject + ParameterManager parameterManager; + + @Inject + Storage storage; + + @Inject + InstrumentStoreService iss; + + @Inject + Workspace workspace; + + @Inject + Console console; + + @Inject + Controller controller; + + @Inject + Coordinator coordinator; + + LinkedPanel constantQPanel; + + CQLayer cqLayer; + + LinkedPanel cqPanel; + + SpectrumLayer noiseFloorLayer; + + PitchDetectLayer pdLayer; + LinkedPanel pitchDetectPanel; + SpectrumLayer spectrumLayer; + LinkedPanel spectrumPanel; + ToneMapView toneMapView; + String currentToneMapViewType; + + Map toneMapViews = new HashMap<>(); + + static final Integer[] fftWindowSizes = { 256, 512, 1024, 2048, 4096, 8192 }; + static final Integer[] inputSampleRate = { 8000, 11025, 22050, 44100, 48000, 96000, 192000 }; + + static final String[] toneMapViewTypesMode3 = new String[] { Cell.CellTypes.AUDIO_CQ.name(), + Cell.CellTypes.AUDIO_SYNTHESIS.name(), Cell.CellTypes.AUDIO_CQ_ORIGIN.name(), + Cell.CellTypes.AUDIO_CQ_MICRO_TONE.name(), Cell.CellTypes.AUDIO_TUNER_PEAKS.name(), + Cell.CellTypes.AUDIO_SPECTRAL_PEAKS.name(), Cell.CellTypes.AUDIO_PITCH.name(), + Cell.CellTypes.AUDIO_PHASE.name(), Cell.CellTypes.AUDIO_YIN.name(), Cell.CellTypes.AUDIO_SACF.name(), + Cell.CellTypes.AUDIO_MFCC.name(), Cell.CellTypes.AUDIO_CEPSTRUM.name(), Cell.CellTypes.AUDIO_NOTATE.name(), + Cell.CellTypes.AUDIO_NOTATE.name() + "_PEAKS", Cell.CellTypes.AUDIO_NOTATE.name() + "_SPECTRAL", + Cell.CellTypes.AUDIO_INTEGRATE.name(), Cell.CellTypes.AUDIO_INTEGRATE.name() + "_PEAKS", + Cell.CellTypes.AUDIO_INTEGRATE.name() + "_SPECTRAL", Cell.CellTypes.AUDIO_ONSET.name(), + Cell.CellTypes.AUDIO_PERCUSSION.name(), Cell.CellTypes.AUDIO_ONSET.name() + "_SMOOTHED", + Cell.CellTypes.AUDIO_HPS.name(), Cell.CellTypes.AUDIO_HPS.name() + "_HARMONIC_MASK", + Cell.CellTypes.AUDIO_HPS.name() + "_PERCUSSION_MASK", Cell.CellTypes.AUDIO_HPS.name() + "_HARMONIC", + Cell.CellTypes.AUDIO_HPS.name() + "_PERCUSSION", Cell.CellTypes.AUDIO_PRE_CHROMA.name(), + Cell.CellTypes.AUDIO_POST_CHROMA.name(), Cell.CellTypes.AUDIO_BEAT.name() }; + + static final String[] toneMapViewTypesMode2 = new String[] { Cell.CellTypes.AUDIO_CQ.name(), + Cell.CellTypes.AUDIO_SYNTHESIS.name(), Cell.CellTypes.AUDIO_INTEGRATE.name(), + Cell.CellTypes.AUDIO_NOTATE.name() }; + + File inputFile; + + JPanel diagnosticsPanel; + + ChromaView chromaView; + + BeatsView beatsView; + + JFrame mainframe; + + JPanel beatsPanel; + + JTextField audioFeatureIntervalInput; + JTextField timeAxisOffsetInput; + JTextField pitchAxisOffsetInput; + JTextField timeAxisRangeInput; + JTextField pitchAxisRangeInput; + JComboBox toneMapViewComboBox; + JCheckBox playMidiSwitchCB; + JCheckBox playAudioSwitchCB; + JTextField voicePlayerLowThresholdInput; + JTextField voicePlayerHighThresholdInput; + JTextField voicePlayerDelayInput; + JTextField frameNumberInput; + JTextField toneMapViewLowThresholdInput; + JTextField toneMapViewHighThresholdInput; + JTextField audioOffsetInput; + JTextField audioRangeInput; + JCheckBox recordSwitchCB; + JCheckBox playResynthSwitchCB; + TimeFramePanel timeFramePanel; + JButton chooseFileButton; + JButton startFileProcessingButton; + JButton startListeningButton; + JButton stopListeningButton; + JButton playAudioButton; + JButton playStreamButton; + JCheckBox playPeaksSwitchCB; + AbstractButton showPeaksSwitchCB; + JCheckBox showPowerSwitchCB; + JCheckBox showLogSwitchCB; + JCheckBox trackWriteSwitchCB; + JPanel visorPanel; + JFrame mainFrame; + Container upperPane; + JPanel contentPane; + JLabel statusLabel; + JLabel fileNameLabel; + JTextField hearingMinFreqCentsInput; + JTextField hearingMaxFreqCentsInput; + JCheckBox updateThresholdSwitchCB; + JCheckBox showColourSwitchCB; + JCheckBox silentWriteSwitchCB; + JCheckBox pausePlaySwitchCB; + JCheckBox midiSynthTracksSwitchCB; + JCheckBox showStatsSwitchCB; + JCheckBox midiPlayLogSwitchCB; + JTextField voicePlayerLogFactorInput; + JTextField voicePlayerGlissandoRangeInput; + + JTextField audioTimeStretchInput; + JTextField audioGainInput; + JTextField persistenceModeInput; + JTextField voicePlayerRepeatInput; + JCheckBox loopSaveSwitchCB; + JCheckBox midiPlayVolumeSwitchCB; + JCheckBox showNotesSwitchCB; + JCheckBox showChordsSwitchCB; + JCheckBox showBeatsSwitchCB; + JButton resetSystemButton; + JButton parametersButton; + JButton synthButton; + JButton updateViewButton; + JSplitPane toneMapViewTopPane; + JSplitPane toneMapViewBottomPane; + JComboBox fftWindowSizeComboBox; + JComboBox inputSampleRateCombobox; + + private JCheckBox showBaseSwitchCB; + + private JCheckBox resampleSwitchCB; + + private JTextField padBeforeInput; + + private JTextField padAfterInput; + + private JTextField audioPitchShiftInput; + + private JDialog parameterDialog; + + private boolean parameterDialogOpen; + + private ParametersPanel parameterPanel; + + private JDialog synthDialog; + + private boolean synthDialogOpen; + + protected SynthPanel synthPanel; + + private JCheckBox playMidiDeviceSwitchCB; + + private JCheckBox streamSaveSwitchCB; + + private JTextField streamIndexInput; + + private JTextField playStartOffsetInput; + + private JTextField playEndOffsetInput; + + private JTextField searchCountInput; + + private JCheckBox cortexShortCircuitSwitchCB; + + private JCheckBox playMidiDeviceChannelSwitchCB; + + @Override + public void startUp() { + LOG.severe(">>Using SwingDesktopVisor"); + EventQueue.invokeLater(() -> { + buildMainFrame(); + }); + } + + @Override + public void shutdown() { + EventQueue.invokeLater(() -> { + closeMainFrame(); + }); + } + + public void updateStatusMessage(String message) { + statusLabel.setText(message); + } + + protected void buildMainFrame() { + FlatMaterialDesignDarkIJTheme.setup(); + FlatLaf.setUseNativeWindowDecorations(true); + mainFrame = new JFrame(); + mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + mainFrame.setTitle("The Instrument"); + + buildContent(); + + initialise(mainFrame); + + upperPane.add(getContentPanel(), BorderLayout.CENTER); + + final int inset = 10; + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + mainFrame.setBounds(inset, inset, screenSize.width - inset * 2, screenSize.height - inset * 2); + mainFrame.pack(); + mainFrame.setVisible(true); + mainFrame.setExtendedState(mainFrame.getExtendedState() | Frame.MAXIMIZED_BOTH); + } + + protected void closeMainFrame() { + mainFrame.setVisible(false); + mainframe.dispose(); + } + + private void showStackTraceDialog(Throwable throwable, String title, String message) { + Window window = DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); + showStackTraceDialog(throwable, window, title, message); + } + + private void showEmailStatusInfoDialog(String title, String message) { + Window window = DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); + showEmailStatusInfoDialog(window, title, message); + } + + private void showStatusInfoDialog(String title, String message) { + Window window = DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); + showStatusInfoDialog(window, title, message); + } + + /** + * show stack trace dialog when exception throws + * + * @param throwable + * @param parentComponent + * @param title + * @param message + */ + private void showStackTraceDialog(Throwable throwable, Component parentComponent, String title, String message) { + final String more = "More"; + // create stack strace panel + JPanel labelPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + JLabel label = new JLabel(more + ">>"); + labelPanel.add(label); + + JTextArea straceTa = new JTextArea(); + final JScrollPane taPane = new JScrollPane(straceTa); + taPane.setPreferredSize(new Dimension(360, 240)); + taPane.setVisible(false); + // print stack trace into textarea + ByteArrayOutputStream out = new ByteArrayOutputStream(); + throwable.printStackTrace(new PrintStream(out)); + straceTa.setForeground(Color.RED); + straceTa.setText(new String(out.toByteArray())); + + final JPanel stracePanel = new JPanel(new BorderLayout()); + stracePanel.add(labelPanel, BorderLayout.NORTH); + stracePanel.add(taPane, BorderLayout.CENTER); + + label.setForeground(Color.BLUE); + label.setCursor(new Cursor(Cursor.HAND_CURSOR)); + label.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + JLabel tmpLab = (JLabel) e.getSource(); + if (tmpLab.getText().equals(more + ">>")) { + tmpLab.setText("<<" + more); + taPane.setVisible(true); + } else { + tmpLab.setText(more + ">>"); + taPane.setVisible(false); + } + SwingUtilities.getWindowAncestor(taPane).pack(); + }; + }); + + JPanel panel = new JPanel(new BorderLayout()); + panel.add(new JLabel(message), BorderLayout.NORTH); + panel.add(stracePanel, BorderLayout.CENTER); + + JOptionPane pane = new JOptionPane(panel, JOptionPane.ERROR_MESSAGE); + JDialog dialog = pane.createDialog(parentComponent, title); + int maxWidth = Toolkit.getDefaultToolkit().getScreenSize().width * 2 / 3; + if (dialog.getWidth() > maxWidth) { + dialog.setSize(new Dimension(maxWidth, dialog.getHeight())); + setLocationRelativeTo(dialog, parentComponent); + } + dialog.setResizable(true); + dialog.setVisible(true); + dialog.dispose(); + } + + private void showStatusInfoDialog(Component parentComponent, String title, String message) { + final String more = "More"; + // create stack strace panel + JPanel labelPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + JLabel label = new JLabel(more + ">>"); + labelPanel.add(label); + + JTextArea straceTa = new JTextArea(); + final JScrollPane taPane = new JScrollPane(straceTa); + taPane.setPreferredSize(new Dimension(360, 240)); + taPane.setVisible(false); + straceTa.setForeground(Color.RED); + straceTa.setText("Status Info"); + + final JPanel stracePanel = new JPanel(new BorderLayout()); + stracePanel.add(labelPanel, BorderLayout.NORTH); + stracePanel.add(taPane, BorderLayout.CENTER); + + label.setForeground(Color.BLUE); + label.setCursor(new Cursor(Cursor.HAND_CURSOR)); + label.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + JLabel tmpLab = (JLabel) e.getSource(); + if (tmpLab.getText().equals(more + ">>")) { + tmpLab.setText("<<" + more); + taPane.setVisible(true); + } else { + tmpLab.setText(more + ">>"); + taPane.setVisible(false); + } + SwingUtilities.getWindowAncestor(taPane).pack(); + }; + }); + + JPanel panel = new JPanel(new BorderLayout()); + panel.add(new JLabel(message), BorderLayout.NORTH); + panel.add(stracePanel, BorderLayout.CENTER); + + JOptionPane pane = new JOptionPane(panel, JOptionPane.ERROR_MESSAGE); + JDialog dialog = pane.createDialog(parentComponent, title); + int maxWidth = Toolkit.getDefaultToolkit().getScreenSize().width * 2 / 3; + if (dialog.getWidth() > maxWidth) { + dialog.setSize(new Dimension(maxWidth, dialog.getHeight())); + setLocationRelativeTo(dialog, parentComponent); + } + dialog.setResizable(true); + dialog.setVisible(true); + dialog.dispose(); + } + + private void showEmailStatusInfoDialog(Component parentComponent, String title, String message) { + final String more = "More"; + // create stack strace panel + JPanel labelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + + JButton emailSendButton = new JButton("Send Email"); + + JLabel emailSenderAddressLabel = new JLabel("Sender Email address: "); + JTextField emailSenderAddressInput = new JTextField(4); + emailSenderAddressInput.setPreferredSize(null); + emailSenderAddressInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + emailSendButton.setEnabled(true); + } + }); + + emailSendButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + // String result = + // controller.sendStatusInfoEmail(emailSenderAddressInput.getText()); + // statusLabel.setText(result); + } + }); + emailSendButton.setEnabled(false); + + labelPanel.add(emailSenderAddressLabel); + labelPanel.add(emailSenderAddressInput); + labelPanel.add(emailSendButton); + + JPanel panel = new JPanel(new BorderLayout()); + panel.add(labelPanel, BorderLayout.CENTER); + + JOptionPane pane = new JOptionPane(panel, JOptionPane.INFORMATION_MESSAGE); + JDialog dialog = pane.createDialog(parentComponent, title); + int maxWidth = Toolkit.getDefaultToolkit().getScreenSize().width * 2 / 3; + if (dialog.getWidth() > maxWidth) { + dialog.setSize(new Dimension(maxWidth, dialog.getHeight())); + setLocationRelativeTo(dialog, parentComponent); + } + dialog.setResizable(true); + dialog.setVisible(true); + dialog.dispose(); + } + + /** + * set c1 location relative to c2 + * + * @param c1 + * @param c2 + */ + private void setLocationRelativeTo(Component c1, Component c2) { + Container root = null; + + if (c2 != null) { + if (c2 instanceof Window) { + root = (Container) c2; + } else { + Container parent; + for (parent = c2.getParent(); parent != null; parent = parent.getParent()) { + if (parent instanceof Window) { + root = parent; + break; + } + } + } + } + + if ((c2 != null && !c2.isShowing()) || root == null || !root.isShowing()) { + Dimension paneSize = c1.getSize(); + + Point centerPoint = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint(); + c1.setLocation(centerPoint.x - paneSize.width / 2, centerPoint.y - paneSize.height / 2); + } else { + Dimension invokerSize = c2.getSize(); + Point invokerScreenLocation = c2.getLocation(); // by longrm: + // c2.getLocationOnScreen(); + + Rectangle windowBounds = c1.getBounds(); + int dx = invokerScreenLocation.x + ((invokerSize.width - windowBounds.width) >> 1); + int dy = invokerScreenLocation.y + ((invokerSize.height - windowBounds.height) >> 1); + Rectangle ss = root.getGraphicsConfiguration().getBounds(); + + // Adjust for bottom edge being offscreen + if (dy + windowBounds.height > ss.y + ss.height) { + dy = ss.y + ss.height - windowBounds.height; + if (invokerScreenLocation.x - ss.x + invokerSize.width / 2 < ss.width / 2) { + dx = invokerScreenLocation.x + invokerSize.width; + } else { + dx = invokerScreenLocation.x - windowBounds.width; + } + } + + // Avoid being placed off the edge of the screen + if (dx + windowBounds.width > ss.x + ss.width) { + dx = ss.x + ss.width - windowBounds.width; + } + if (dx < ss.x) + dx = ss.x; + if (dy < ss.y) + dy = ss.y; + + c1.setLocation(dx, dy); + } + } + + private void buildContent() { + + contentPane = new JPanel(); + + upperPane = new JPanel(); + JPanel statusPane = new JPanel(); + JPanel lowerPane = new JPanel(); + + statusLabel = new JLabel("Ready"); + JButton showStatusInfoButton = new JButton("Show Status Info"); + + showStatusInfoButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + String s = e.getActionCommand(); + Throwable t = workspace.getInstrumentSessionManager().getCurrentSession().getException(); + if (t != null) { + showStackTraceDialog(t, "StatusInfo", "Instrument Exception"); + } else { + showStatusInfoDialog("StatusInfo", "Instrument OK"); + } + } + }); + + statusLabel = new JLabel("Ready"); + + JButton dumpStatusInfoButton = new JButton("Dump Status Info"); + + dumpStatusInfoButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + String result = controller.dumpStatusInfo(); + statusLabel.setText(result); + } + }); + + contentPane.setLayout(new BorderLayout()); + + final int inset1 = 45; + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + contentPane.setPreferredSize(new Dimension(screenSize.width - inset1 * 2, screenSize.height - inset1 * 2)); + + EmptyBorder eb = new EmptyBorder(5, 5, 5, 5); + BevelBorder bb = new BevelBorder(BevelBorder.LOWERED); + CompoundBorder cb = new CompoundBorder(eb, bb); + contentPane.setBorder(cb); + + fileNameLabel = new JLabel(""); + + statusPane.add(showStatusInfoButton, BorderLayout.WEST); + statusPane.add(dumpStatusInfoButton, BorderLayout.WEST); + statusPane.add(statusLabel, BorderLayout.CENTER); + statusPane.add(new JLabel(" Current File:"), BorderLayout.EAST); + statusPane.add(fileNameLabel, BorderLayout.EAST); + + EmptyBorder eb1 = new EmptyBorder(2, 2, 2, 2); + BevelBorder bb1 = new BevelBorder(BevelBorder.LOWERED); + CompoundBorder cb1 = new CompoundBorder(eb1, bb1); + statusPane.setBorder(cb1); + + upperPane.setLayout(new BorderLayout()); + + lowerPane.setLayout(new BorderLayout()); + lowerPane.add(statusPane, BorderLayout.CENTER); + + contentPane.add(upperPane, BorderLayout.CENTER); + contentPane.add(lowerPane, BorderLayout.SOUTH); + contentPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); + + mainFrame.setContentPane(contentPane); + } + + public void initialise(JFrame mainframe) { + visorPanel = new JPanel(); + this.mainframe = mainframe; + this.visorPanel.setLayout(new BorderLayout()); + JPanel topPanel = buildTopPanel(); + JPanel bottomPanel = buildBottomPanel(); + JScrollPane graphPanel = buildGraphPanel(); + this.visorPanel.add(topPanel, BorderLayout.NORTH); + this.visorPanel.add(graphPanel, BorderLayout.CENTER); + this.visorPanel.add(bottomPanel, BorderLayout.SOUTH); + } + + private JPanel buildTopPanel() { + + JPanel panel = new JPanel(new GridLayout(1, 1)); + + JPanel controlPanel = buildControlPanel(); + panel.add(controlPanel); + + return panel; + } + + private JPanel buildBottomPanel() { + + JPanel panel = new JPanel(new GridLayout(1, 1)); + + JPanel viewControlPanel = buildViewControlPanel(); + panel.add(viewControlPanel); + + return panel; + } + + private JScrollPane buildGraphPanel() { + JPanel panel = new JPanel(); + panel.setLayout(new GridLayout(1, 1)); + + JPanel leftGraphPanel = new JPanel(); + leftGraphPanel.setLayout(new BorderLayout()); + + JPanel rightGraphPanel = new JPanel(); + rightGraphPanel.setLayout(new BorderLayout()); + + JSplitPane splitPane = new JSplitPane(SwingConstants.VERTICAL, new JScrollPane(leftGraphPanel), + new JScrollPane(rightGraphPanel)); + + Toolkit myScreen = Toolkit.getDefaultToolkit(); + Dimension screenSize = myScreen.getScreenSize(); + int screenHeight = screenSize.height; + int screenWidth = screenSize.width; + + splitPane.setOneTouchExpandable(true); + splitPane.setDividerLocation((int) ((double) screenWidth * 0.7)); + + JPanel chromaPanel = buildChromaPanel(); + JPanel spectrumsPanel = buildSpectrumsPanel(); + JPanel beatsPanel = buildBeatsPanel(); + toneMapViewTopPane = new JSplitPane(SwingConstants.HORIZONTAL, new JScrollPane(chromaPanel), + new JScrollPane(beatsPanel)); + toneMapViewBottomPane = new JSplitPane(SwingConstants.HORIZONTAL, new JScrollPane(toneMapViewTopPane), + new JScrollPane(spectrumsPanel)); + toneMapViewTopPane.setOneTouchExpandable(true); + toneMapViewBottomPane.setOneTouchExpandable(true); + + leftGraphPanel.add(toneMapViewBottomPane, BorderLayout.CENTER); + + if (toneMapViewTopPane != null) { + if (parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_CHORDS)) { + if (parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_BEATS)) { + toneMapViewBottomPane.setDividerLocation((int) ((double) screenHeight * 0.3)); + toneMapViewTopPane.setDividerLocation((int) ((double) screenHeight * 0.18)); + } else { + toneMapViewBottomPane.setDividerLocation((int) ((double) screenHeight * 0.3)); + toneMapViewTopPane.setDividerLocation((int) ((double) screenHeight * 0.18)); + } + } else { + if (parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_BEATS)) { + toneMapViewBottomPane.setDividerLocation((int) ((double) screenHeight * 0.2)); + toneMapViewTopPane.setDividerLocation(0); + } else { + toneMapViewBottomPane.setDividerLocation(0); + toneMapViewTopPane.setDividerLocation(0); + } + } + } + diagnosticsPanel = buildDiagnosticsPanel(); + rightGraphPanel.add(diagnosticsPanel, BorderLayout.CENTER); + Dimension minimumSize = new Dimension(100, 1000); + panel.setMinimumSize(minimumSize); + panel.add(splitPane); + return new JScrollPane(panel); + } + + private JPanel buildSpectrumsPanel() { + JPanel panel = new JPanel(new BorderLayout()); + JTabbedPane toneMapTabbedPane = new JTabbedPane(); + toneMapTabbedPane + .setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(10, 10, 10, 10), new EtchedBorder())); // BorderFactory.createLineBorder(Color.black)); + JPanel toneMapLayerPanel = createToneMapLayerPanel(); + toneMapTabbedPane.addTab("ToneMap", toneMapLayerPanel); + cqPanel = createCQPanel(); + toneMapTabbedPane.addTab("CQ", cqPanel); + pitchDetectPanel = createPitchDetectPanel(); + toneMapTabbedPane.addTab("Pitch", pitchDetectPanel); + panel.add(toneMapTabbedPane, BorderLayout.CENTER); + return panel; + } + + private JPanel buildChromaPanel() { + JPanel panel = new JPanel(new BorderLayout()); + JTabbedPane chromaTabbedPane = new JTabbedPane(); + chromaTabbedPane + .setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(10, 10, 10, 10), new EtchedBorder())); + chromaView = new ChromaView(); + JPanel chromaSynthPanel = new JPanel(new BorderLayout()); + chromaSynthPanel.add(chromaView, BorderLayout.CENTER); + chromaSynthPanel.setBackground(Color.BLACK); + chromaTabbedPane.addTab("Chroma", chromaSynthPanel); + panel.add(chromaTabbedPane, BorderLayout.CENTER); + return panel; + } + + private JPanel buildBeatsPanel() { + JPanel panel = new JPanel(new BorderLayout()); + JTabbedPane beatsTabbedPane = new JTabbedPane(); + beatsTabbedPane + .setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(10, 10, 10, 10), new EtchedBorder())); // BorderFactory.createLineBorder(Color.black)); + + beatsView = new BeatsView(); + JPanel beatsPanel = new JPanel(new BorderLayout()); + beatsPanel.add(beatsView, BorderLayout.CENTER); + beatsPanel.setBackground(Color.BLACK); + beatsTabbedPane.addTab("Beats", beatsPanel); + + panel.add(beatsTabbedPane, BorderLayout.CENTER); + return panel; + } + + private JPanel buildDiagnosticsPanel() { + JPanel panel = new JPanel(new BorderLayout()); + JTabbedPane diagnosticsTabbedPane = new JTabbedPane(); + diagnosticsTabbedPane + .setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(10, 10, 10, 10), new EtchedBorder())); // BorderFactory.createLineBorder(Color.black)); + timeFramePanel = new TimeFramePanel(); + diagnosticsTabbedPane.addTab("ToneMap Frame", timeFramePanel); + spectrumPanel = createSpectrumPanel(); + diagnosticsTabbedPane.addTab("Spectrum", spectrumPanel); + panel.add(diagnosticsTabbedPane, BorderLayout.CENTER); + return panel; + } + + public String getCurrentLocalDateTimeStamp() { + return LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd_HH:mm:ss.SSS")); + } + + private JPanel buildViewControlPanel() { + + JPanel panel = new JPanel(new BorderLayout()); + panel.setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(10, 10, 10, 10), new EtchedBorder())); + + JPanel graphControlPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + + JPanel graphViewControlPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + + JLabel frameNumberLabel = new JLabel("Frame #: "); + frameNumberInput = new JTextField(4); + frameNumberInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JTextField textField = (JTextField) e.getSource(); + String newValue = textField.getText(); + int frame = Integer.valueOf(newValue); + if (frame < 1) { + frameNumberInput.setText("1"); + } + showFrame(Integer.valueOf(newValue)); + } + }); + frameNumberInput.setText("0"); + graphControlPanel.add(frameNumberLabel); + graphControlPanel.add(frameNumberInput); + + toneMapViewComboBox = new JComboBox<>(); + + if (parameterManager + .getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_TONEMAP_PERSISTENCE_MODE) <= 2) { + Arrays.asList(toneMapViewTypesMode2).stream().forEach(entry -> toneMapViewComboBox.addItem(entry)); + } else { + Arrays.asList(toneMapViewTypesMode3).stream().forEach(entry -> toneMapViewComboBox.addItem(entry)); + } + + toneMapViewComboBox.setEnabled(false); + toneMapViewComboBox.setSelectedItem(Cell.CellTypes.AUDIO_SYNTHESIS.name()); + toneMapViewComboBox.setEnabled(true); + currentToneMapViewType = Cell.CellTypes.AUDIO_SYNTHESIS.name(); + + toneMapViewComboBox.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String value = String.valueOf(toneMapViewComboBox.getSelectedItem()); + if (value != null) { + currentToneMapViewType = value; + switchToneMapView(); + } + } + }); + + graphControlPanel.add(new JLabel("ToneMap View: ")); + graphControlPanel.add(toneMapViewComboBox); + + JLabel timeAxisOffsetLabel = new JLabel("Time Axis Offset ms: "); + timeAxisOffsetInput = new JTextField(4); + timeAxisOffsetInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JTextField textField = (JTextField) e.getSource(); + String newValue = textField.getText(); + newValue = parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_OFFSET, + newValue); + textField.setText(newValue); + refreshMapViews(); + switchToneMapView(); + } + }); + + timeAxisOffsetInput + .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_OFFSET)); + graphControlPanel.add(timeAxisOffsetLabel); + graphControlPanel.add(timeAxisOffsetInput); + + JLabel pitchAxisOffsetLabel = new JLabel("Pitch Axis Offset ms: "); + pitchAxisOffsetInput = new JTextField(4); + pitchAxisOffsetInput.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + JTextField textField = (JTextField) e.getSource(); + String newValue = textField.getText(); + newValue = parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_PITCH_AXIS_OFFSET, + newValue); + textField.setText(newValue); + refreshMapViews(); + } + }); + + pitchAxisOffsetInput + .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_VIEW_PITCH_AXIS_OFFSET)); + graphControlPanel.add(pitchAxisOffsetLabel); + graphControlPanel.add(pitchAxisOffsetInput); + + JLabel timeAxisRangeLabel = new JLabel("Time Axis Range ms: "); + timeAxisRangeInput = new JTextField(4); + timeAxisRangeInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JTextField textField = (JTextField) e.getSource(); + String newValue = textField.getText(); + newValue = parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_RANGE, + newValue); + textField.setText(newValue); + refreshMapViews(); + + } + }); + timeAxisRangeInput + .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_RANGE)); + graphControlPanel.add(timeAxisRangeLabel); + graphControlPanel.add(timeAxisRangeInput); + + JLabel pitchAxisRangeLabel = new JLabel("Pitch Axis Range ms: "); + pitchAxisRangeInput = new JTextField(4); + pitchAxisRangeInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JTextField textField = (JTextField) e.getSource(); + String newValue = textField.getText(); + newValue = parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_PITCH_AXIS_RANGE, + newValue); + textField.setText(newValue); + refreshMapViews(); + } + }); + + pitchAxisRangeInput + .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_VIEW_PITCH_AXIS_RANGE)); + graphControlPanel.add(pitchAxisRangeLabel); + graphControlPanel.add(pitchAxisRangeInput); + + panel.add(graphControlPanel, BorderLayout.NORTH); + + showColourSwitchCB = new JCheckBox("showColourSwitchCB"); + showColourSwitchCB.setText("Colour"); + showColourSwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_COLOUR, + Boolean.toString(newValue)); + refreshMapViews(); + } + }); + showColourSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_COLOUR)); + graphViewControlPanel.add(showColourSwitchCB); + + showPeaksSwitchCB = new JCheckBox("showPeaksSwitchCB"); + showPeaksSwitchCB.setText("Peaks"); + showPeaksSwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_PEAKS, + Boolean.toString(newValue)); + refreshMapViews(); + } + }); + showPeaksSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_PEAKS)); + graphViewControlPanel.add(showPeaksSwitchCB); + + showPowerSwitchCB = new JCheckBox("showPowerSwitchCB"); + showPowerSwitchCB.setText("Power"); + showPowerSwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_POWER, + Boolean.toString(newValue)); + refreshMapViews(); + } + }); + showPowerSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_POWER)); + graphViewControlPanel.add(showPowerSwitchCB); + + showNotesSwitchCB = new JCheckBox("showNotesSwitchCB"); + showNotesSwitchCB.setText("Notes"); + showNotesSwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_NOTES, + Boolean.toString(newValue)); + refreshMapViews(); + } + }); + showNotesSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_NOTES)); + graphViewControlPanel.add(showNotesSwitchCB); + + showChordsSwitchCB = new JCheckBox("showChordsSwitchCB"); + showChordsSwitchCB.setText("Chords"); + showChordsSwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_CHORDS, + Boolean.toString(newValue)); + Toolkit myScreen = Toolkit.getDefaultToolkit(); + Dimension screenSize = myScreen.getScreenSize(); + int screenHeight = screenSize.height; + if (toneMapViewTopPane != null) { + if (parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_CHORDS)) { + if (parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_BEATS)) { + toneMapViewBottomPane.setDividerLocation((int) ((double) screenHeight * 0.3)); + toneMapViewTopPane.setDividerLocation((int) ((double) screenHeight * 0.18)); + } else { + toneMapViewBottomPane.setDividerLocation((int) ((double) screenHeight * 0.3)); + toneMapViewTopPane.setDividerLocation((int) ((double) screenHeight * 0.18)); + } + } else { + if (parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_BEATS)) { + toneMapViewBottomPane.setDividerLocation((int) ((double) screenHeight * 0.2)); + toneMapViewTopPane.setDividerLocation(0); + } else { + toneMapViewBottomPane.setDividerLocation(0); + toneMapViewTopPane.setDividerLocation(0); + } + } + } + refreshMapViews(); + } + }); + showChordsSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_CHORDS)); + graphViewControlPanel.add(showChordsSwitchCB); + + showBaseSwitchCB = new JCheckBox("showBaseSwitchCB"); + showBaseSwitchCB.setText("Base"); + showBaseSwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_BASE, + Boolean.toString(newValue)); + refreshMapViews(); + } + }); + showBaseSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_BASE)); + graphViewControlPanel.add(showBaseSwitchCB); + + showBeatsSwitchCB = new JCheckBox("showBeatsSwitchCB"); + showBeatsSwitchCB.setText("Beats"); + showBeatsSwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_BEATS, + Boolean.toString(newValue)); + Toolkit myScreen = Toolkit.getDefaultToolkit(); + Dimension screenSize = myScreen.getScreenSize(); + int screenHeight = screenSize.height; + if (toneMapViewTopPane != null) { + if (parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_CHORDS)) { + if (parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_BEATS)) { + toneMapViewBottomPane.setDividerLocation((int) ((double) screenHeight * 0.3)); + toneMapViewTopPane.setDividerLocation((int) ((double) screenHeight * 0.18)); + } else { + toneMapViewBottomPane.setDividerLocation((int) ((double) screenHeight * 0.3)); + toneMapViewTopPane.setDividerLocation((int) ((double) screenHeight * 0.18)); + } + } else { + if (parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_BEATS)) { + toneMapViewBottomPane.setDividerLocation((int) ((double) screenHeight * 0.2)); + toneMapViewTopPane.setDividerLocation(0); + } else { + toneMapViewBottomPane.setDividerLocation(0); + toneMapViewTopPane.setDividerLocation(0); + } + } + } + refreshMapViews(); + } + }); + showBeatsSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_BEATS)); + graphViewControlPanel.add(showBeatsSwitchCB); + + showStatsSwitchCB = new JCheckBox("showStatsSwitchCB"); + showStatsSwitchCB.setText("Stats"); + showStatsSwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_STATS, + Boolean.toString(newValue)); + refreshMapViews(); + } + }); + showStatsSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_STATS)); + graphViewControlPanel.add(showStatsSwitchCB); + + showLogSwitchCB = new JCheckBox("showLogSwitchCB"); + showLogSwitchCB.setText("Logn"); + showLogSwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_LOG, + Boolean.toString(newValue)); + refreshMapViews(); + } + }); + showLogSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_LOG)); + graphViewControlPanel.add(showLogSwitchCB); + + updateViewButton = new JButton("Update"); + updateViewButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + updateViewThresholds(); + toneMapViewHighThresholdInput.setText( + parameterManager.getParameter(InstrumentParameterNames.MONITOR_TONEMAP_VIEW_HIGH_THRESHOLD)); + } + }); + graphViewControlPanel.add(updateViewButton); + + JLabel toneMapViewLowThresholdLabel = new JLabel("Low: "); + toneMapViewLowThresholdInput = new JTextField(4); + toneMapViewLowThresholdInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JTextField textField = (JTextField) e.getSource(); + String newValue = textField.getText(); + newValue = parameterManager.setParameter(InstrumentParameterNames.MONITOR_TONEMAP_VIEW_LOW_THRESHOLD, + newValue); + textField.setText(newValue); + refreshMapViews(); + } + }); + + toneMapViewLowThresholdInput + .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_TONEMAP_VIEW_LOW_THRESHOLD)); + graphViewControlPanel.add(toneMapViewLowThresholdLabel); + graphViewControlPanel.add(toneMapViewLowThresholdInput); + + JLabel toneMapViewHighThresholdLabel = new JLabel("High: "); + toneMapViewHighThresholdInput = new JTextField(4); + toneMapViewHighThresholdInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JTextField textField = (JTextField) e.getSource(); + String newValue = textField.getText(); + newValue = parameterManager.setParameter(InstrumentParameterNames.MONITOR_TONEMAP_VIEW_HIGH_THRESHOLD, + newValue); + textField.setText(newValue); + refreshMapViews(); + } + }); + + toneMapViewHighThresholdInput + .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_TONEMAP_VIEW_HIGH_THRESHOLD)); + graphViewControlPanel.add(toneMapViewHighThresholdLabel); + graphViewControlPanel.add(toneMapViewHighThresholdInput); + + panel.add(graphViewControlPanel, BorderLayout.CENTER); + + return panel; + } + + @Override + public 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(); + parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_OFFSET, "0"); + int timeRange = toneMapView.getMaxTime(); + formatter = new Formatter(); + formatter.format("%d", timeRange); + parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_RANGE, formatter.toString()); + formatter.close(); + int minPitchCents = toneMapView.getMinPitchCents(); + formatter = new Formatter(); + formatter.format("%d", minPitchCents); + // parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_PITCH_AXIS_OFFSET, + // formatter.toString()); + formatter.close(); + int maxPitchCents = toneMapView.getMaxPitchCents(); + formatter = new Formatter(); + formatter.format("%d", maxPitchCents); + // parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_PITCH_AXIS_RANGE, + // formatter.toString()); + formatter.close(); + timeAxisOffsetInput + .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_OFFSET)); + // pitchAxisOffsetInput + // .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_VIEW_PITCH_AXIS_OFFSET)); + timeAxisRangeInput + .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_RANGE)); + // pitchAxisRangeInput + // .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_VIEW_PITCH_AXIS_RANGE)); + + } + refreshMapViews(); + } + + protected boolean parseIntsegerTextField(JTextField textField, int min, int max, String parameterName) { + try { + int value = Integer.parseInt(textField.getText()); + if (value >= min && value <= max) { + parameterManager.setParameter(parameterName, Integer.toString(value)); + return true; + } else { + textField.setText(parameterManager.getParameter(parameterName)); + } + } catch (Exception ex) { + textField.setText(parameterManager.getParameter(parameterName)); + } + return false; + } + + private JPanel buildControlPanel() { + + JPanel panel = new JPanel(new BorderLayout()); + panel.setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(10, 10, 10, 10), new EtchedBorder())); + + JPanel actionPanel = new JPanel(new BorderLayout()); + // JPanel actionPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + + JPanel actionEastPanel = new JPanel(); + JPanel actionCenterPanel = new JPanel(); + JPanel actionWestPanel = new JPanel(); + actionPanel.add(actionEastPanel, BorderLayout.EAST); + actionPanel.add(actionCenterPanel, BorderLayout.CENTER); + actionPanel.add(actionWestPanel, BorderLayout.WEST); + + JPanel voicePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + + JPanel instrumentPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + + resetSystemButton = new JButton("Reset"); + resetSystemButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent arg0) { + instrument.reset(); + updateStatusMessage("System Reset"); + } + }); + + actionWestPanel.add(resetSystemButton); + + final JButton helpButton = new JButton("Help"); + + helpButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + String s = e.getActionCommand(); + String message = """ + For information about using this application - please see - https://github.com/jimomulloy/instrument/wiki + + In case of status errors, please use the "Dump Status Info" button to create a text file containing information + about the current status of the application. + + If you wish me to investigate please send this file as an attachment to my email address jimomulloy@gmail.com. + + Thank you for using this early prototype version, hope you have fun with it. + """; + if (s.equals("Help")) { + JOptionPane.showMessageDialog(mainframe, message); + } + } + }); + actionWestPanel.add(helpButton); + + parametersButton = new JButton("Parameters"); + + parameterDialog = new JDialog(mainframe, "Parameters"); + parameterDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); + parameterDialog.addWindowListener(new WindowAdapter() { + public void windowClosed(WindowEvent e) { + parameterDialogOpen = false; + } + + public void windowClosing(WindowEvent e) { + parameterDialogOpen = false; + parameterDialog.getContentPane().removeAll(); + parameterDialog.dispose(); + } + }); + parametersButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + String s = e.getActionCommand(); + if (s.equals("Parameters")) { + + if (!parameterDialogOpen) { + parameterDialog.getContentPane().removeAll(); + + JPanel dialogPanel = new JPanel(new BorderLayout()); + + parameterPanel = new ParametersPanel(); + + dialogPanel.setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(20, 20, 20, 20), + new EtchedBorder())); + + dialogPanel.add(new JScrollPane(parameterPanel), BorderLayout.CENTER); + + parameterDialog.add(dialogPanel); + + Toolkit myScreen = Toolkit.getDefaultToolkit(); + Dimension screenSize = myScreen.getScreenSize(); + int screenHeight = screenSize.height; + int screenWidth = screenSize.width; + + parameterDialog.setSize((int) ((double) screenWidth * 0.7), + (int) ((double) screenHeight * 0.7)); + + parameterDialog.setVisible(true); + + parameterDialog.pack(); + + parameterDialogOpen = true; + + } + } + } + }); + + actionWestPanel.add(parametersButton); + + synthButton = new JButton("Synth Controls"); + + synthDialog = new JDialog(mainframe, "Synth"); + synthDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); + synthDialog.addWindowListener(new WindowAdapter() { + public void windowClosed(WindowEvent e) { + synthDialogOpen = false; + } + + public void windowClosing(WindowEvent e) { + synthDialogOpen = false; + synthDialog.getContentPane().removeAll(); + synthDialog.dispose(); + } + }); + synthButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + String s = e.getActionCommand(); + if (s.equals("Synth Controls")) { + + if (!synthDialogOpen) { + synthDialog.getContentPane().removeAll(); + + JPanel dialogPanel = new JPanel(new BorderLayout()); + + synthPanel = new SynthPanel(); + dialogPanel.setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(20, 20, 20, 20), + new EtchedBorder())); + + dialogPanel.add(new JScrollPane(synthPanel), BorderLayout.CENTER); + + synthDialog.add(dialogPanel); + + Toolkit myScreen = Toolkit.getDefaultToolkit(); + Dimension screenSize = myScreen.getScreenSize(); + int screenHeight = screenSize.height; + int screenWidth = screenSize.width; + + synthDialog.setSize((int) ((double) screenWidth * 0.7), (int) ((double) screenHeight * 0.7)); + + synthDialog.setVisible(true); + + synthDialog.pack(); + + synthDialogOpen = true; + + } + } + } + }); + actionWestPanel.add(synthButton); + + final JFileChooser fileChooser = new JFileChooser(new File(getAudioSourceFileFolder())); + chooseFileButton = new JButton("Open"); + startFileProcessingButton = new JButton("Start"); + startListeningButton = new JButton("Listen"); + stopListeningButton = new JButton("Stop"); + playAudioButton = new JButton("Play Audio"); + playStreamButton = new JButton("Play Stream"); + fileChooser.setSelectedFile(new File(getAudioSourceFileFolder(), getDefaultAudioFile())); + chooseFileButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent arg0) { + int returnVal = fileChooser.showOpenDialog(visorPanel); + if (returnVal == JFileChooser.APPROVE_OPTION) { + inputFile = fileChooser.getSelectedFile(); + String fileName = inputFile.getAbsolutePath(); + fileNameLabel.setText(inputFile.getName()); + startListeningButton.setEnabled(false); + startFileProcessingButton.setEnabled(false); + stopListeningButton.setEnabled(true); + chooseFileButton.setEnabled(false); + frameNumberInput.setEnabled(false); + // timeAxisOffsetInput.setText("0"); + workspace.getInstrumentSessionManager().getCurrentSession().clearException(); + parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_OFFSET, "0"); + parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_DEFAULT_FILE, + inputFile.getName()); + toneMapViews.remove(currentToneMapViewType); + refreshMapViews(); + resetToneMapView(); + try { + Instrument.getInstance().getCoordinator().getHearing().startAudioFileStream(fileName); + updateStatusMessage("Choosen file: " + inputFile); + } catch (Exception e) { + LOG.log(Level.SEVERE, "Error choosing file :" + inputFile, e); + coordinator.getHearing().stopAudioStream(); + coordinator.getVoice().clear(coordinator.getHearing().getStreamId()); + startFileProcessingButton.setEnabled(true); + startListeningButton.setEnabled(true); + // stopListeningButton.setEnabled(false); + chooseFileButton.setEnabled(true); + frameNumberInput.setEnabled(true); + updateStatusMessage("Error choosing file :" + inputFile + ", " + e.getMessage()); + } + } + } + }); + + actionCenterPanel.add(chooseFileButton); + + startFileProcessingButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent arg0) { + try { + inputFile = fileChooser.getSelectedFile(); + String fileName = inputFile.getAbsolutePath(); + fileNameLabel.setText(inputFile.getName()); + startListeningButton.setEnabled(false); + startFileProcessingButton.setEnabled(false); + stopListeningButton.setEnabled(true); + chooseFileButton.setEnabled(false); + frameNumberInput.setEnabled(false); + // timeAxisOffsetInput.setText("0"); + workspace.getInstrumentSessionManager().getCurrentSession().clearException(); + parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_OFFSET, "0"); + parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_DEFAULT_FILE, + inputFile.getName()); + toneMapViews.remove(currentToneMapViewType); + refreshMapViews(); + resetToneMapView(); + Instrument.getInstance().getCoordinator().getHearing().startAudioFileStream(fileName); + updateStatusMessage("Started file: " + inputFile); + } catch (Exception e) { + LOG.log(Level.SEVERE, "Error starting file :" + inputFile, e); + coordinator.getHearing().stopAudioStream(); + coordinator.getVoice().clear(coordinator.getHearing().getStreamId()); + startFileProcessingButton.setEnabled(true); + startListeningButton.setEnabled(true); + // stopListeningButton.setEnabled(false); + chooseFileButton.setEnabled(true); + frameNumberInput.setEnabled(true); + updateStatusMessage("Error starting file :" + inputFile + ", " + e.getMessage()); + } + } + }); + + startListeningButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent arg0) { + try { + String fileName = "instrument_recording_" + System.currentTimeMillis() + ".wav"; + String filePath = getAudioRecordFileFolder() + "/" + fileName; + startListeningButton.setEnabled(false); + startFileProcessingButton.setEnabled(false); + fileNameLabel.setText(fileName); + stopListeningButton.setEnabled(true); + chooseFileButton.setEnabled(false); + frameNumberInput.setEnabled(false); + // timeAxisOffsetInput.setText("0"); + workspace.getInstrumentSessionManager().getCurrentSession().clearException(); + parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_OFFSET, "0"); + toneMapViews.remove(currentToneMapViewType); + + if (coordinator.getHearing().getStreamId() != null) { + coordinator.getHearing().stopAudioStream(); + coordinator.getHearing().stopAudioPlayer(); + coordinator.getVoice().clear(coordinator.getHearing().getStreamId()); + coordinator.getVoice().stopStreamPlayer(); + } + + refreshMapViews(); + resetToneMapView(); + + coordinator.getHearing().startAudioLineStream(filePath); + updateStatusMessage("Started listener: " + fileName); + + } catch (LineUnavailableException | IOException e) { + LOG.log(Level.SEVERE, "Error starting listener", e); + coordinator.getHearing().stopAudioStream(); + coordinator.getVoice().clear(coordinator.getHearing().getStreamId()); + startFileProcessingButton.setEnabled(true); + startListeningButton.setEnabled(true); + chooseFileButton.setEnabled(true); + frameNumberInput.setEnabled(true); + updateStatusMessage("Error starting listener :" + e.getMessage()); + } + } + }); + + stopListeningButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent arg0) { + new Thread(() -> { + coordinator.getHearing().stopAudioStream(); + coordinator.getHearing().stopAudioPlayer(); + coordinator.getVoice().clear(coordinator.getHearing().getStreamId()); + coordinator.getVoice().stopStreamPlayer(); + }).start(); + startFileProcessingButton.setEnabled(true); + startListeningButton.setEnabled(true); + playAudioButton.setEnabled(true); + playStreamButton.setEnabled(true); + chooseFileButton.setEnabled(true); + frameNumberInput.setEnabled(true); + updateStatusMessage("Stopped"); + } + }); + + playAudioButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent arg0) { + try { + boolean started = coordinator.getHearing().startAudioPlayer(); + if (started) { + stopListeningButton.setEnabled(true); + } + } catch (Exception e) { + LOG.log(Level.SEVERE, "Error starting listener", e); + coordinator.getHearing().stopAudioStream(); + updateStatusMessage("Error playing audio :" + e.getMessage()); + } + } + }); + + playStreamButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent arg0) { + if (coordinator.getHearing().getStreamId() != null) { + int index = parameterManager + .getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_STREAM_SAVE_INDEX); + final ToneMap synthToneMap = workspace.getAtlas().getSavedToneMap(index); + LOG.severe(">>PLAY ST: " + index + ", " + synthToneMap); + if (synthToneMap != null) { + playStreamButton.setEnabled(false); + new Thread(() -> { + coordinator.getVoice().startStreamPlayer(synthToneMap.getStreamId(), synthToneMap); + }).start(); + stopListeningButton.setEnabled(true); + } + } + } + }); + + actionCenterPanel.add(startFileProcessingButton); + actionCenterPanel.add(startListeningButton); + actionCenterPanel.add(stopListeningButton); + actionCenterPanel.add(playAudioButton); + actionCenterPanel.add(playStreamButton); + playStreamButton.setEnabled(false); + + streamSaveSwitchCB = new JCheckBox("streamSaveSwitchCB"); + streamSaveSwitchCB.setText("Save"); + streamSaveSwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_STREAM_SAVE_SWITCH, + Boolean.toString(newValue)); + refreshMapViews(); + } + }); + streamSaveSwitchCB.setSelected( + parameterManager.getBooleanParameter(InstrumentParameterNames.PERCEPTION_HEARING_STREAM_SAVE_SWITCH)); + actionCenterPanel.add(streamSaveSwitchCB); + + cortexShortCircuitSwitchCB = new JCheckBox("cortexShortCircuitSwitchCB"); + cortexShortCircuitSwitchCB.setText("Short"); + cortexShortCircuitSwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_CORTEX_SHORT_CIRCUIT_SWITCH, + Boolean.toString(newValue)); + if (newValue) { + parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_SYNTHESIS_SWEEP_RANGE, + Integer.toString(10)); + parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_NOTATE_SWEEP_RANGE, + Integer.toString(20)); + parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_SINK_SWEEP_RANGE, + Integer.toString(0)); + } else { + parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_SYNTHESIS_SWEEP_RANGE, + Integer.toString(20)); + parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_NOTATE_SWEEP_RANGE, + Integer.toString(50)); + parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_SINK_SWEEP_RANGE, + Integer.toString(0)); + + } + refreshMapViews(); + } + }); + cortexShortCircuitSwitchCB.setSelected( + parameterManager.getBooleanParameter(InstrumentParameterNames.PERCEPTION_CORTEX_SHORT_CIRCUIT_SWITCH)); + actionCenterPanel.add(cortexShortCircuitSwitchCB); + + JLabel streamIndexLabel = new JLabel("Index: "); + streamIndexInput = new JTextField(4); + streamIndexInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String newValue = streamIndexInput.getText(); + newValue = parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_STREAM_SAVE_INDEX, + newValue); + streamIndexInput.setText(newValue); + } + }); + streamIndexInput + .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_STREAM_SAVE_INDEX)); + actionCenterPanel.add(streamIndexLabel); + actionCenterPanel.add(streamIndexInput); + + JLabel playStartOffsetLabel = new JLabel("Start Offset: "); + playStartOffsetInput = new JTextField(4); + playStartOffsetInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String newValue = playStartOffsetInput.getText(); + newValue = parameterManager + .setParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY_START_OFFSET, newValue); + playStartOffsetInput.setText(newValue); + } + }); + playStartOffsetInput.setText( + parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY_START_OFFSET)); + actionCenterPanel.add(playStartOffsetLabel); + actionCenterPanel.add(playStartOffsetInput); + + JLabel playEndOffsetLabel = new JLabel("End Offset: "); + playEndOffsetInput = new JTextField(4); + playEndOffsetInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String newValue = playEndOffsetInput.getText(); + newValue = parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY_END_OFFSET, + newValue); + playEndOffsetInput.setText(newValue); + } + }); + playEndOffsetInput + .setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY_END_OFFSET)); + actionCenterPanel.add(playEndOffsetLabel); + actionCenterPanel.add(playEndOffsetInput); + + JLabel persistenceModeLabel = new JLabel("Persistence Mode: "); + persistenceModeInput = new JTextField(4); + persistenceModeInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String newValue = persistenceModeInput.getText(); + newValue = parameterManager + .setParameter(InstrumentParameterNames.PERCEPTION_HEARING_TONEMAP_PERSISTENCE_MODE, newValue); + persistenceModeInput.setText(newValue); + if (toneMapViewComboBox != null) { + if (parameterManager.getIntParameter( + InstrumentParameterNames.PERCEPTION_HEARING_TONEMAP_PERSISTENCE_MODE) <= 2) { + toneMapViewComboBox.removeAllItems(); + Arrays.asList(toneMapViewTypesMode2).stream() + .forEach(entry -> toneMapViewComboBox.addItem(entry)); + } else { + toneMapViewComboBox.removeAllItems(); + Arrays.asList(toneMapViewTypesMode3).stream() + .forEach(entry -> toneMapViewComboBox.addItem(entry)); + } + } + } + }); + persistenceModeInput.setText( + parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_TONEMAP_PERSISTENCE_MODE)); + actionEastPanel.add(persistenceModeLabel); + actionEastPanel.add(persistenceModeInput); + + panel.add(actionPanel, BorderLayout.NORTH); + + fftWindowSizeComboBox = new JComboBox<>(fftWindowSizes); + fftWindowSizeComboBox.addActionListener(new ActionListener() { + private Integer fftsize; + + @Override + public void actionPerformed(ActionEvent e) { + @SuppressWarnings("unchecked") + Integer value = (Integer) ((JComboBox) e.getSource()).getSelectedItem(); + fftsize = value; + parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_DEFAULT_WINDOW, + Integer.toString(fftsize)); + } + }); + + fftWindowSizeComboBox.setSelectedIndex(2); + instrumentPanel.add(new JLabel("FFT Window: ")); + instrumentPanel.add(fftWindowSizeComboBox); + + inputSampleRateCombobox = new JComboBox<>(inputSampleRate); + inputSampleRateCombobox.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + @SuppressWarnings("unchecked") + Integer value = (Integer) ((JComboBox) e.getSource()).getSelectedItem(); + Integer sampleRate = value; + parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_DEFAULT_SAMPLE_RATE, + Integer.toString(sampleRate)); + } + }); + inputSampleRateCombobox.setSelectedIndex(3); + instrumentPanel.add(new JLabel("Sample rate: ")); + instrumentPanel.add(inputSampleRateCombobox); + + JLabel audioFeatureIntervalLabel = new JLabel("Interval: "); + audioFeatureIntervalInput = new JTextField(3); + audioFeatureIntervalInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JTextField textField = (JTextField) e.getSource(); + String newValue = textField.getText(); + newValue = parameterManager + .setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_FEATURE_INTERVAL, newValue); + textField.setText(newValue); + } + }); + + resampleSwitchCB = new JCheckBox("resampleSwitchCB"); + resampleSwitchCB.setText("ReS"); + resampleSwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_RESAMPLE, + Boolean.toString(newValue)); + } + }); + + resampleSwitchCB.setSelected( + parameterManager.getBooleanParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_RESAMPLE)); + instrumentPanel.add(resampleSwitchCB); + + audioFeatureIntervalInput.setText( + parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_FEATURE_INTERVAL)); + instrumentPanel.add(audioFeatureIntervalLabel); + instrumentPanel.add(audioFeatureIntervalInput); + + JLabel audioOffsetLabel = new JLabel("Offset: "); + audioOffsetInput = new JTextField(4); + audioOffsetInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JTextField textField = (JTextField) e.getSource(); + String newValue = textField.getText(); + newValue = parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_OFFSET, + newValue); + textField.setText(newValue); + } + }); + + audioOffsetInput + .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_OFFSET)); + instrumentPanel.add(audioOffsetLabel); + instrumentPanel.add(audioOffsetInput); + + audioFeatureIntervalInput.setText( + parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_FEATURE_INTERVAL)); + instrumentPanel.add(audioFeatureIntervalLabel); + instrumentPanel.add(audioFeatureIntervalInput); + + JLabel audioGainLabel = new JLabel("Gain: "); + audioGainInput = new JTextField(3); + audioGainInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JTextField textField = (JTextField) e.getSource(); + String newValue = textField.getText(); + newValue = parameterManager + .setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_GAIN_COMPRESS_FACTOR, newValue); + textField.setText(newValue); + } + }); + + audioGainInput.setText( + parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_GAIN_COMPRESS_FACTOR)); + instrumentPanel.add(audioGainLabel); + instrumentPanel.add(audioGainInput); + + JLabel audioTimeStretchLabel = new JLabel("Stretch: "); + audioTimeStretchInput = new JTextField(3); + audioTimeStretchInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JTextField textField = (JTextField) e.getSource(); + String newValue = textField.getText(); + newValue = parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_TIME_STRETCH, + newValue); + textField.setText(newValue); + } + }); + + audioTimeStretchInput + .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_TIME_STRETCH)); + instrumentPanel.add(audioTimeStretchLabel); + instrumentPanel.add(audioTimeStretchInput); + + JLabel audioPitchShiftLabel = new JLabel("Shift: "); + audioPitchShiftInput = new JTextField(3); + audioPitchShiftInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JTextField textField = (JTextField) e.getSource(); + String newValue = textField.getText(); + newValue = parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_PITCH_SHIFT, + newValue); + textField.setText(newValue); + } + }); + + audioPitchShiftInput + .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_PITCH_SHIFT)); + instrumentPanel.add(audioPitchShiftLabel); + instrumentPanel.add(audioPitchShiftInput); + + JLabel audioRangeLabel = new JLabel("Range: "); + audioRangeInput = new JTextField(4); + audioRangeInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JTextField textField = (JTextField) e.getSource(); + String newValue = textField.getText(); + newValue = parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_RANGE, + newValue); + textField.setText(newValue); + } + }); + + audioRangeInput.setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_RANGE)); + instrumentPanel.add(audioRangeLabel); + instrumentPanel.add(audioRangeInput); + + JLabel padBeforeLabel = new JLabel("Pad Before: "); + padBeforeInput = new JTextField(3); + padBeforeInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JTextField textField = (JTextField) e.getSource(); + String newValue = textField.getText(); + newValue = parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_PAD_BEFORE, + newValue); + textField.setText(newValue); + } + }); + + padBeforeInput + .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_PAD_BEFORE)); + instrumentPanel.add(padBeforeLabel); + instrumentPanel.add(padBeforeInput); + + JLabel padAfterLabel = new JLabel("After: "); + padAfterInput = new JTextField(3); + padAfterInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JTextField textField = (JTextField) e.getSource(); + String newValue = textField.getText(); + newValue = parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_PAD_AFTER, + newValue); + textField.setText(newValue); + } + }); + + padAfterInput + .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_PAD_AFTER)); + instrumentPanel.add(padAfterLabel); + instrumentPanel.add(padAfterInput); + + JLabel hearingMinFreqCentsLabel = new JLabel("Cents Min: "); + hearingMinFreqCentsInput = new JTextField(3); + hearingMinFreqCentsInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String newValue = hearingMinFreqCentsInput.getText(); + newValue = parameterManager + .setParameter(InstrumentParameterNames.PERCEPTION_HEARING_MINIMUM_FREQUENCY_CENTS, newValue); + hearingMinFreqCentsInput.setText(newValue); + } + }); + hearingMinFreqCentsInput.setText( + parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_MINIMUM_FREQUENCY_CENTS)); + instrumentPanel.add(hearingMinFreqCentsLabel); + instrumentPanel.add(hearingMinFreqCentsInput); + + JLabel hearingMaxFreqCentsLabel = new JLabel("Max: "); + hearingMaxFreqCentsInput = new JTextField(3); + hearingMaxFreqCentsInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String newValue = hearingMaxFreqCentsInput.getText(); + newValue = parameterManager + .setParameter(InstrumentParameterNames.PERCEPTION_HEARING_MAXIMUM_FREQUENCY_CENTS, newValue); + hearingMaxFreqCentsInput.setText(newValue); + } + }); + hearingMaxFreqCentsInput.setText( + parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_MAXIMUM_FREQUENCY_CENTS)); + instrumentPanel.add(hearingMaxFreqCentsLabel); + instrumentPanel.add(hearingMaxFreqCentsInput); + + JLabel searchLabel = new JLabel("Search: "); + searchCountInput = new JTextField(3); + searchCountInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String newValue = searchCountInput.getText(); + newValue = parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AI_SEARCH_COUNT, + newValue); + searchCountInput.setText(newValue); + } + }); + searchCountInput + .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AI_SEARCH_COUNT)); + instrumentPanel.add(searchLabel); + instrumentPanel.add(searchCountInput); + + panel.add(instrumentPanel, BorderLayout.CENTER); + + playMidiSwitchCB = new JCheckBox("playMidiSwitchCB"); + playMidiSwitchCB.setText("MIDI"); + playMidiSwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY, + Boolean.toString(newValue)); + } + }); + + playMidiSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY)); + voicePanel.add(playMidiSwitchCB); + + playMidiDeviceSwitchCB = new JCheckBox("playMidiDeviceSwitchCB"); + playMidiDeviceSwitchCB.setText("DP"); + playMidiDeviceSwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_DEVICE_PLAY_SWITCH, + Boolean.toString(newValue)); + } + }); + + playMidiDeviceSwitchCB.setSelected( + parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_DEVICE_PLAY_SWITCH)); + voicePanel.add(playMidiDeviceSwitchCB); + + playMidiDeviceChannelSwitchCB = new JCheckBox("playMidiDeviceChannelSwitchCB"); + playMidiDeviceChannelSwitchCB.setText("DC"); + playMidiDeviceChannelSwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_DEVICE_CHANNEL_SWITCH, + Boolean.toString(newValue)); + } + }); + + playMidiDeviceChannelSwitchCB.setSelected( + parameterManager + .getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_DEVICE_CHANNEL_SWITCH)); + voicePanel.add(playMidiDeviceChannelSwitchCB); + + playAudioSwitchCB = new JCheckBox("playAudioSwitchCB"); + playAudioSwitchCB.setText("Audio"); + playAudioSwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_AUDIO_PLAY, + Boolean.toString(newValue)); + } + }); + + playAudioSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_AUDIO_PLAY)); + voicePanel.add(playAudioSwitchCB); + + playResynthSwitchCB = new JCheckBox("playResynthSwitchCB"); + playResynthSwitchCB.setText("Resynth"); + playResynthSwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_RESYNTH_PLAY, + Boolean.toString(newValue)); + } + }); + + playResynthSwitchCB.setSelected( + parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_RESYNTH_PLAY)); + voicePanel.add(playResynthSwitchCB); + + playPeaksSwitchCB = new JCheckBox("playPeaksSwitchCB"); + playPeaksSwitchCB.setText("PEAKS"); + playPeaksSwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_PLAY_PEAKS, + Boolean.toString(newValue)); + } + }); + + playPeaksSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_PLAY_PEAKS)); + voicePanel.add(playPeaksSwitchCB); + + pausePlaySwitchCB = new JCheckBox("pausePlaySwitchCB"); + pausePlaySwitchCB.setText("Pause"); + pausePlaySwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_PAUSE_PLAY_SWITCH, + Boolean.toString(newValue)); + } + }); + + pausePlaySwitchCB.setSelected( + parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_PAUSE_PLAY_SWITCH)); + voicePanel.add(pausePlaySwitchCB); + + JLabel spacer1Label = new JLabel(" "); + voicePanel.add(spacer1Label); + + JLabel voicePlayerDelayLabel = new JLabel("Delay: "); + voicePlayerDelayInput = new JTextField(4); + voicePlayerDelayInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String newValue = voicePlayerDelayInput.getText(); + newValue = parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_DELAY, newValue); + voicePlayerDelayInput.setText(newValue); + } + }); + + voicePlayerDelayInput.setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_DELAY)); + voicePanel.add(voicePlayerDelayLabel); + voicePanel.add(voicePlayerDelayInput); + + JLabel voicePlayerRepeatLabel = new JLabel("Repeat: "); + voicePlayerRepeatInput = new JTextField(4); + voicePlayerRepeatInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String newValue = voicePlayerRepeatInput.getText(); + newValue = parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_PLAY_REPEAT, + newValue); + voicePlayerRepeatInput.setText(newValue); + } + }); + + voicePlayerRepeatInput + .setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_PLAY_REPEAT)); + voicePanel.add(voicePlayerRepeatLabel); + voicePanel.add(voicePlayerRepeatInput); + + loopSaveSwitchCB = new JCheckBox("loopSaveSwitchCB"); + loopSaveSwitchCB.setText("Loops"); + loopSaveSwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_LOOP_SAVE, + Boolean.toString(newValue)); + } + }); + + loopSaveSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_LOOP_SAVE)); + voicePanel.add(loopSaveSwitchCB); + + JLabel voicePlayerLowThresholdLabel = new JLabel("Low Threshold: "); + voicePlayerLowThresholdInput = new JTextField(4); + voicePlayerLowThresholdInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JTextField textField = (JTextField) e.getSource(); + String newValue = textField.getText(); + newValue = parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_LOW_THRESHOLD, + newValue); + voicePlayerLowThresholdInput.setText(newValue); + } + }); + + voicePlayerLowThresholdInput + .setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_LOW_THRESHOLD)); + voicePanel.add(voicePlayerLowThresholdLabel); + voicePanel.add(voicePlayerLowThresholdInput); + + JLabel voicePlayerHighThresholdLabel = new JLabel("High Threshold: "); + voicePlayerHighThresholdInput = new JTextField(4); + voicePlayerHighThresholdInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JTextField textField = (JTextField) e.getSource(); + String newValue = textField.getText(); + newValue = parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_HIGH_THRESHOLD, + newValue); + voicePlayerHighThresholdInput.setText(newValue); + } + }); + + voicePlayerHighThresholdInput + .setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_HIGH_THRESHOLD)); + voicePanel.add(voicePlayerHighThresholdLabel); + voicePanel.add(voicePlayerHighThresholdInput); + + midiPlayVolumeSwitchCB = new JCheckBox("midiPlayVolumeSwitchCB"); + midiPlayVolumeSwitchCB.setText("Volume"); + midiPlayVolumeSwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY_VOLUME_SWITCH, + Boolean.toString(newValue)); + } + }); + + midiPlayVolumeSwitchCB.setSelected( + parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY_VOLUME_SWITCH)); + voicePanel.add(midiPlayVolumeSwitchCB); + + midiPlayLogSwitchCB = new JCheckBox("midiPlayLogSwitchCB"); + midiPlayLogSwitchCB.setText("Log"); + midiPlayLogSwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY_LOG_SWITCH, + Boolean.toString(newValue)); + } + }); + + midiPlayLogSwitchCB.setSelected( + parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY_LOG_SWITCH)); + voicePanel.add(midiPlayLogSwitchCB); + + JLabel voicePlayerLogFactorLabel = new JLabel("Log Factor: "); + voicePlayerLogFactorInput = new JTextField(4); + voicePlayerLogFactorInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JTextField textField = (JTextField) e.getSource(); + String newValue = textField.getText(); + newValue = parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_LOG_FACTOR, newValue); + voicePlayerLogFactorInput.setText(newValue); + } + }); + + voicePlayerLogFactorInput + .setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_LOG_FACTOR)); + voicePanel.add(voicePlayerLogFactorLabel); + voicePanel.add(voicePlayerLogFactorInput); + + JLabel voicePlayerGlissandoRangeLabel = new JLabel("Glissando: "); + voicePlayerGlissandoRangeInput = new JTextField(4); + voicePlayerGlissandoRangeInput.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JTextField textField = (JTextField) e.getSource(); + String newValue = textField.getText(); + newValue = parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_GLISSANDO_RANGE, + newValue); + voicePlayerGlissandoRangeInput.setText(newValue); + } + }); + + voicePlayerGlissandoRangeInput + .setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_GLISSANDO_RANGE)); + voicePanel.add(voicePlayerGlissandoRangeLabel); + voicePanel.add(voicePlayerGlissandoRangeInput); + + voicePanel.add(new JLabel(" ")); + + midiSynthTracksSwitchCB = new JCheckBox("midiSynthTracksSwitchCB"); + midiSynthTracksSwitchCB.setText("Synth"); + midiSynthTracksSwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_SYNTH_TRACKS_SWITCH, + Boolean.toString(newValue)); + } + }); + + midiSynthTracksSwitchCB.setSelected(parameterManager + .getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_SYNTH_TRACKS_SWITCH)); + voicePanel.add(midiSynthTracksSwitchCB); + + silentWriteSwitchCB = new JCheckBox("silentWriteCB"); + silentWriteSwitchCB.setText("Silent Write"); + silentWriteSwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_SILENT_WRITE, + Boolean.toString(newValue)); + } + }); + + silentWriteSwitchCB.setSelected( + parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_SILENT_WRITE)); + voicePanel.add(silentWriteSwitchCB); + + trackWriteSwitchCB = new JCheckBox("trackWriteCB"); + trackWriteSwitchCB.setText("Track Write"); + trackWriteSwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.ACTUATION_VOICE_TRACK_WRITE_SWITCH, + Boolean.toString(newValue)); + } + }); + + trackWriteSwitchCB.setSelected( + parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_TRACK_WRITE_SWITCH)); + voicePanel.add(trackWriteSwitchCB); + + recordSwitchCB = new JCheckBox("recordSwitchCB"); + recordSwitchCB.setText("Record"); + recordSwitchCB.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + JCheckBox cb = (JCheckBox) e.getSource(); + boolean newValue = cb.isSelected(); + parameterManager.setParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_RECORD_SWITCH, + Boolean.toString(newValue)); + } + }); + + recordSwitchCB.setSelected( + parameterManager.getBooleanParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_RECORD_SWITCH)); + voicePanel.add(recordSwitchCB); + + panel.add(voicePanel, BorderLayout.SOUTH); + + return panel; + } + + private String getAudioSourceFileFolder() { + return parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_SOURCE_DIRECTORY); + } + + private String getDefaultAudioFile() { + return parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_DEFAULT_FILE); + } + + private String getAudioRecordFileFolder() { + String baseDir = storage.getObjectStorage().getBasePath(); + return Paths + .get(baseDir, + parameterManager + .getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_RECORD_DIRECTORY)) + .toString(); + } + + @Override + public void audioFeatureFrameAdded(AudioFeatureFrame audioFeatureFrame) { + updateView(audioFeatureFrame); + } + + @Override + public void audioFeatureFrameChanged(AudioFeatureFrame audioFeatureFrame) { + updateView(audioFeatureFrame); + } + + @Override + public void clearView() { + toneMapViews.clear(); + cqLayer.clear(); + pdLayer.clear(); + this.cqPanel.repaint(); + this.pitchDetectPanel.repaint(); + this.frameNumberInput.setText("0"); + } + + @Override + public void showFrame(int frame) { + if (frame > 0) { + if (toneMapViews.containsKey(currentToneMapViewType)) { + ToneMap currentToneMap = toneMapViews.get(currentToneMapViewType); + ToneTimeFrame toneTimeFrame = currentToneMap.getTimeFrame(frame); + if (toneTimeFrame != null) { + updateTimeFrameView(toneTimeFrame); + int timeOffset = (int) (toneTimeFrame.getStartTime() * 1000.0); + parameterManager.setParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_OFFSET, + Integer.toString(timeOffset)); + timeAxisOffsetInput.setText(Integer.toString(timeOffset)); + refreshMapViews(); + updateSpectrumView(toneTimeFrame, parameterManager + .getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_DEFAULT_WINDOW)); + } + } + } + } + + @Override + public void updateTimeFrameView(ToneTimeFrame data) { + timeFramePanel.paint(data); + timeFramePanel.repaint(); + } + + @Override + @SuppressWarnings("unchecked") + public void updateToneMapView(ToneMap toneMap, String toneMapViewType) { + + List timeFrames = new ArrayList<>(); + ToneTimeFrame ttf = toneMap.getTimeFrame(); + if (ttf != null) { + double fromTime = (ttf.getStartTime() - 1.0) >= 0 ? ttf.getStartTime() - 1.0 : 0; + + while (ttf != null && ttf.getStartTime() >= fromTime) { + timeFrames.add(ttf); + ttf = toneMap.getPreviousTimeFrame(ttf.getStartTime()); + } + for (ToneTimeFrame ttfv : timeFrames) { + updateToneMapView(toneMap, ttfv, toneMapViewType); + } + } + } + + @Override + @SuppressWarnings("unchecked") + public void updateToneMapView(ToneMap toneMap, ToneTimeFrame ttf, String toneMapViewType) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + if (!toneMapViews.containsKey(toneMapViewType)) { + toneMapViews.put(toneMapViewType, toneMap); + if (toneMapViewType.equals(currentToneMapViewType)) { + toneMapView.renderToneMap(toneMap); + beatsView.renderToneMap(toneMap); + chromaView.renderToneMap(toneMap); + } + } else if (toneMapView.getToneMap() != null && toneMapViews.get(toneMapViewType) != null + && !toneMapViews.get(toneMapViewType).getKey().equals(toneMapView.getToneMap().getKey())) { + toneMapViews.put(toneMapViewType, toneMap); + if (toneMapViewType.equals(currentToneMapViewType)) { + toneMapView.renderToneMap(toneMap); + beatsView.renderToneMap(toneMap); + chromaView.renderToneMap(toneMap); + } + } else if (toneMapViewType.equals(currentToneMapViewType) && toneMapView != null) { + toneMapView.updateToneMap(toneMap, ttf); + beatsView.updateToneMap(toneMap, ttf); + chromaView.updateToneMap(toneMap, ttf); + } + updateTimeFrameView(ttf); + } + }); + } + + private void switchToneMapView() { + if (toneMapViews.containsKey(currentToneMapViewType)) { + toneMapView.renderToneMap(toneMapViews.get(currentToneMapViewType)); + updateTimeFrameView(toneMapViews.get(currentToneMapViewType).getTimeFrame()); + } + } + + private void resetToneMapView() { + if (toneMapViews.containsKey(currentToneMapViewType)) { + toneMapView.renderToneMap(toneMapViews.get(currentToneMapViewType)); + updateTimeFrameView(toneMapViews.get(currentToneMapViewType).getTimeFrame()); + chromaView.renderToneMap(toneMapViews.get(currentToneMapViewType)); + beatsView.renderToneMap(toneMapViews.get(currentToneMapViewType)); + } else { + toneMapView.clear(); + chromaView.clear(); + beatsView.clear(); + } + } + + @Override + public void updateSpectrumView(ToneTimeFrame toneTimeFrame, int windowSize) { + if (toneTimeFrame != null) { + float[] spectrum = toneTimeFrame.extractFFTSpectrum(windowSize).getSpectrum(); + for (int i = 0; i < spectrum.length; i++) { + spectrum[i] *= 100; + } + spectrumLayer.clearPeaks(); + spectrumLayer.setSpectrum(spectrum); + spectrumPanel.repaint(); + } + } + + private LinkedPanel createCQPanel() { + CoordinateSystem constantQCS = getCoordinateSystem(AxisUnit.FREQUENCY); + constantQCS.setMax(Axis.X, 20000); + constantQPanel = new LinkedPanel(constantQCS); + cqLayer = new CQLayer(constantQCS); + constantQPanel.addLayer(new BackgroundLayer(constantQCS)); + constantQPanel.addLayer(cqLayer); + constantQPanel.addLayer(new VerticalFrequencyAxisLayer(constantQCS)); + constantQPanel.addLayer(new ZoomMouseListenerLayer()); + constantQPanel.addLayer(new DragMouseListenerLayer(constantQCS)); + constantQPanel.addLayer(new SelectionLayer(constantQCS)); + constantQPanel.addLayer(new TimeAxisLayer(constantQCS)); + + LegendLayer legend = new LegendLayer(constantQCS, 110); + constantQPanel.addLayer(legend); + legend.addEntry("ConstantQ", Color.BLACK); + legend.addEntry("Pitch estimations", Color.RED); + ViewPortChangedListener listener = new ViewPortChangedListener() { + @Override + public void viewPortChanged(ViewPort newViewPort) { + constantQPanel.repaint(); + } + }; + constantQPanel.getViewPort().addViewPortChangedListener(listener); + return constantQPanel; + } + + private LinkedPanel createPitchDetectPanel() { + CoordinateSystem cs = getCoordinateSystem(AxisUnit.FREQUENCY); + cs.setMax(Axis.X, 20000); + pitchDetectPanel = new LinkedPanel(cs); + pitchDetectPanel.addLayer(new BackgroundLayer(cs)); + pdLayer = new PitchDetectLayer(cs); + pitchDetectPanel.addLayer(pdLayer); + pitchDetectPanel.addLayer(new VerticalFrequencyAxisLayer(cs)); + pitchDetectPanel.addLayer(new ZoomMouseListenerLayer()); + pitchDetectPanel.addLayer(new DragMouseListenerLayer(cs)); + pitchDetectPanel.addLayer(new SelectionLayer(cs)); + pitchDetectPanel.addLayer(new TimeAxisLayer(cs)); + + LegendLayer legend = new LegendLayer(cs, 110); + pitchDetectPanel.addLayer(legend); + legend.addEntry("Pitch", Color.BLACK); + ViewPortChangedListener listener = new ViewPortChangedListener() { + @Override + public void viewPortChanged(ViewPort newViewPort) { + pitchDetectPanel.repaint(); + } + }; + pitchDetectPanel.getViewPort().addViewPortChangedListener(listener); + return pitchDetectPanel; + } + + private LinkedPanel createSpectrumPanel() { + CoordinateSystem cs = new CoordinateSystem(AxisUnit.FREQUENCY, AxisUnit.AMPLITUDE, 0, 1000, false); + cs.setMax(Axis.X, 4800); + cs.setMax(Axis.X, 13200); + spectrumLayer = new SpectrumLayer(cs, + parameterManager.getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_DEFAULT_WINDOW), + parameterManager.getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_DEFAULT_SAMPLE_RATE), + Color.black); + // noiseFloorLayer = new SpectrumLayer(cs, + // parameterManager.getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_SP_WINDOW), + // parameterManager.getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_DEFAULT_SAMPLE_RATE), + // Color.gray); + + spectrumPanel = new LinkedPanel(cs); + spectrumPanel.addLayer(new ZoomMouseListenerLayer()); + spectrumPanel.addLayer(new DragMouseListenerLayer(cs)); + spectrumPanel.addLayer(new BackgroundLayer(cs)); + spectrumPanel.addLayer(new AmplitudeAxisLayer(cs)); + + spectrumPanel.addLayer(new SelectionLayer(cs)); + spectrumPanel.addLayer(new HorizontalFrequencyAxisLayer(cs)); + spectrumPanel.addLayer(spectrumLayer); + // spectrumPanel.addLayer(noiseFloorLayer); + + spectrumPanel.getViewPort().addViewPortChangedListener(new ViewPortChangedListener() { + boolean painting = false; + + @Override + public void viewPortChanged(ViewPort newViewPort) { + if (!painting) { + painting = true; + spectrumPanel.repaint(); + painting = false; + } + } + }); + return spectrumPanel; + } + + private JPanel createToneMapLayerPanel() { + toneMapView = new ToneMapView(); + JPanel tmContainer = new JPanel(new BorderLayout()); + tmContainer.add(toneMapView, BorderLayout.CENTER); + tmContainer.setBackground(Color.BLACK); + return tmContainer; + } + + private CoordinateSystem getCoordinateSystem(AxisUnit yUnits) { + float minValue = -1000; + float maxValue = 1000; + if (yUnits == AxisUnit.FREQUENCY) { + minValue = 400; + maxValue = 12000; + } + return new CoordinateSystem(yUnits, minValue, maxValue); + } + + private void updateView(AudioFeatureFrame audioFeatureFrame) { + cqLayer.update(audioFeatureFrame); + pdLayer.update(audioFeatureFrame); + cqPanel.repaint(); + pitchDetectPanel.repaint(); + this.frameNumberInput.setText(Integer.toString(audioFeatureFrame.getFrameSequence())); + } + + @Override + public void audioStopped() { + startFileProcessingButton.setEnabled(true); + startListeningButton.setEnabled(true); + // stopListeningButton.setEnabled(false); + chooseFileButton.setEnabled(true); + frameNumberInput.setEnabled(true); + } + + private static class CQLayer implements Layer { + + private float binHeight; + private float[] binStartingPointsInCents; + + private float binWidth; + private TreeMap cqFeatures; + private final CoordinateSystem cs; + + public CQLayer(CoordinateSystem cs) { + this.cs = cs; + } + + @Override + public void draw(Graphics2D graphics) { + + if (cqFeatures != null) { + Map spectralInfoSubMap = cqFeatures.subMap(cs.getMin(Axis.X) / 1000.0, + cs.getMax(Axis.X) / 1000.0); + float minValue = 5 / 1000000.0F; + float currentMaxSpectralEnergy = 0; + for (Map.Entry column : spectralInfoSubMap.entrySet()) { + float[] spectralEnergy = column.getValue(); + for (float element : spectralEnergy) { + float magnitude = Math.max(minValue, element); + magnitude = (float) Math.log10(1 + (100.0 * magnitude)); + currentMaxSpectralEnergy = Math.max(currentMaxSpectralEnergy, magnitude); + } + } + for (Map.Entry column : spectralInfoSubMap.entrySet()) { + double timeStart = column.getKey();// in seconds + float[] spectralEnergy = column.getValue();// in cents + // draw the pixels + for (int i = 0; i < spectralEnergy.length; i++) { + Color color = Color.black; + float centsStartingPoint = binStartingPointsInCents[i]; + // only draw the visible frequency range + if (centsStartingPoint >= cs.getMin(Axis.Y) && centsStartingPoint <= cs.getMax(Axis.Y)) { + // int greyValue = 255 - (int) + // (Math.log1p(spectralEnergy[i]) + // / Math.log1p(currentMaxSpectralEnergy) * 255); + float magnitude = Math.max(minValue, spectralEnergy[i]); + magnitude = (float) Math.log10(1 + (100.0 * magnitude)); + int greyValue = 255 - (int) (magnitude / (currentMaxSpectralEnergy) * 255); + greyValue = Math.max(0, greyValue); + color = new Color(greyValue, greyValue, greyValue); + graphics.setColor(color); + graphics.fillRect((int) Math.round(timeStart * 1000), Math.round(centsStartingPoint), + Math.round(binWidth * 1000), (int) Math.ceil(binHeight)); + } + } + } + } + } + + public void clear() { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + cqFeatures = new TreeMap<>(); + } + }); + } + + @Override + public String getName() { + return "CQ Layer"; + } + + public void update(AudioFeatureFrame audioFeatureFrame) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + ConstantQSource cqs = audioFeatureFrame.getConstantQFeatures().getSource(); + binStartingPointsInCents = cqs.getBinStartingPointsInCents(); + binWidth = cqs.getBinWidth(); + binHeight = cqs.getBinHeight(); + Map fs = audioFeatureFrame.getConstantQFeatures().getFeatures(); + if (cqFeatures == null) { + cqFeatures = new TreeMap<>(); + } + for (java.util.Map.Entry entry : fs.entrySet()) { + cqFeatures.put(entry.getKey(), entry.getValue()); + } + } + }); + } + } + + private static class TimeFramePanel extends JPanel { + + private ToneTimeFrame toneTimeFrame; + + public TimeFramePanel() { + setMinimumSize(new Dimension(80, 60)); + } + + public void paint(ToneTimeFrame toneTimeFrame) { + this.toneTimeFrame = toneTimeFrame; + } + + @Override + public void paintComponent(Graphics g) { + super.paintComponent(g); // paint background + g.setColor(Color.BLACK); + g.fillRect(0, 0, getWidth(), getHeight()); + g.setColor(Color.WHITE); + if (toneTimeFrame != null) { + float width = getWidth(); + float height = getHeight(); + ToneMapElement[] elements = toneTimeFrame.getElements(); + double xInc = width / elements.length; + double yInc = height / 1.0; + int x = 0; + int y = 0; + for (int i = 0; i < elements.length; i++) { + ToneMapElement element = elements[i]; + x = (int) (i * xInc); + y = (int) height - 1; + if ((toneTimeFrame.getMaxAmplitude() - toneTimeFrame.getMinAmplitude()) > 0.1) { + y = (int) (height - (yInc * ((element.amplitude - toneTimeFrame.getMinAmplitude()) + / (toneTimeFrame.getMaxAmplitude() - toneTimeFrame.getMinAmplitude())))); + } + g.drawLine(x, (int) height - 1, x, y); + } + } + } + } + + private static class PitchDetectLayer implements Layer { + + private float binHeight; + private float[] binStartingPointsInCents; + private float binWidth; + private final CoordinateSystem cs; + TreeMap features; + + public PitchDetectLayer(CoordinateSystem cs) { + this.cs = cs; + } + + @Override + public void draw(Graphics2D graphics) { + + if (features != null) { + + Map spSubMap = features.subMap(cs.getMin(Axis.X) / 1000.0, + cs.getMax(Axis.X) / 1000.0); + double maxAmp = 0.00001; + for (Entry column : spSubMap.entrySet()) { + + double timeStart = column.getKey();// in seconds + SpectrogramInfo spectrogramInfo = column.getValue();// in + // cents + float pitch = spectrogramInfo.getPitchDetectionResult().getPitch(); // -1? + float[] amplitudes = spectrogramInfo.getAmplitudes(); + // draw the pixels + for (int i = 0; i < amplitudes.length; i++) { + Color color = Color.black; + float centsStartingPoint = binStartingPointsInCents[i]; + // only draw the visible frequency range + if (centsStartingPoint >= cs.getMin(Axis.Y) && centsStartingPoint <= cs.getMax(Axis.Y)) { + // int greyValue = 255 - (int) + // (Math.log1p(spectralEnergy[i]) + // / Math.log1p(currentMaxSpectralEnergy) * 255); + if (amplitudes[i] > maxAmp) { + maxAmp = amplitudes[i]; + } + int greyValue = 255 - (int) (amplitudes[i] / (maxAmp) * 255); + greyValue = Math.max(0, greyValue); + color = new Color(greyValue, greyValue, greyValue); + graphics.setColor(color); + graphics.fillRect((int) Math.round(timeStart * 1000), Math.round(centsStartingPoint), + Math.round(binWidth * 1000), (int) Math.ceil(binHeight)); + + } + } + + if (pitch > -1) { + double cents = PitchConverter.hertzToAbsoluteCent(pitch); + Color color = Color.red; + // only draw the visible frequency range + if (cents >= cs.getMin(Axis.Y) && cents <= cs.getMax(Axis.Y)) { + // int greyValue = (int) (255F * probability); + // greyValue = Math.max(0, greyValue); + // color = new Color(greyValue, greyValue, + // greyValue); + graphics.setColor(color); + graphics.fillRect((int) Math.round(timeStart * 1000), (int) cents, Math.round(40), + (int) Math.ceil(100)); + } + } + } + } + } + + @Override + public String getName() { + return "Pitch Detect Layer"; + } + + public void clear() { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + features = new TreeMap<>(); + } + }); + } + + public void update(AudioFeatureFrame audioFeatureFrame) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + TreeMap fs; + PitchDetectorSource pds; + pds = audioFeatureFrame.getPitchDetectorFeatures().getSource(); + binStartingPointsInCents = pds.getBinStartingPointsInCents(); + binWidth = pds.getBinWidth(); + binHeight = pds.getBinHeight(); + fs = audioFeatureFrame.getPitchDetectorFeatures().getFeatures(); + if (features == null) { + features = new TreeMap<>(); + } + for (Entry entry : fs.entrySet()) { + features.put(entry.getKey(), entry.getValue()); + } + } + }); + } + } + + private void refreshMapViews() { + if (toneMapView != null) { + toneMapView.updateAxis(); + chromaView.updateAxis(); + beatsView.updateAxis(); + } + } + + protected void repaintSpectralInfo(AudioFeatureFrame audioFeatureFrame) { + TreeMap fs; + SpectralPeaksSource sps = audioFeatureFrame.getSpectralPeaksFeatures().getSource(); + fs = audioFeatureFrame.getSpectralPeaksFeatures().getFeatures(); + spectrumLayer.clearPeaks(); + for (Entry entry : fs.entrySet()) { + spectrumLayer.setSpectrum(entry.getValue().getMagnitudes()); + spectrumPanel.repaint(); + } + } + + @Override + public void updateParameters() { + timeAxisOffsetInput + .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_OFFSET)); + pitchAxisOffsetInput + .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_VIEW_PITCH_AXIS_OFFSET)); + timeAxisRangeInput + .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_VIEW_TIME_AXIS_RANGE)); + pitchAxisRangeInput + .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_VIEW_PITCH_AXIS_RANGE)); + showColourSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_COLOUR)); + showPeaksSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_PEAKS)); + showPowerSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_POWER)); + showNotesSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_NOTES)); + showChordsSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_CHORDS)); + showBaseSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_BASE)); + showBeatsSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_BEATS)); + showStatsSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_STATS)); + showLogSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.MONITOR_VIEW_SHOW_LOG)); + toneMapViewLowThresholdInput + .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_TONEMAP_VIEW_LOW_THRESHOLD)); + toneMapViewHighThresholdInput + .setText(parameterManager.getParameter(InstrumentParameterNames.MONITOR_TONEMAP_VIEW_HIGH_THRESHOLD)); + recordSwitchCB.setSelected( + parameterManager.getBooleanParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_RECORD_SWITCH)); + audioFeatureIntervalInput.setText( + parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_FEATURE_INTERVAL)); + audioOffsetInput + .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_OFFSET)); + audioGainInput.setText( + parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_GAIN_COMPRESS_FACTOR)); + audioTimeStretchInput + .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_TIME_STRETCH)); + audioRangeInput.setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_RANGE)); + audioPitchShiftInput + .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_PITCH_SHIFT)); + padBeforeInput + .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_PAD_BEFORE)); + padAfterInput + .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_PAD_AFTER)); + resampleSwitchCB.setSelected( + parameterManager.getBooleanParameter(InstrumentParameterNames.PERCEPTION_HEARING_AUDIO_RESAMPLE)); + hearingMinFreqCentsInput.setText( + parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_MINIMUM_FREQUENCY_CENTS)); + hearingMaxFreqCentsInput.setText( + parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_MAXIMUM_FREQUENCY_CENTS)); + searchCountInput + .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_AI_SEARCH_COUNT)); + persistenceModeInput.setText( + parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_TONEMAP_PERSISTENCE_MODE)); + playMidiSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY)); + playMidiDeviceSwitchCB.setSelected( + parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_DEVICE_PLAY_SWITCH)); + playMidiDeviceChannelSwitchCB.setSelected( + parameterManager + .getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_DEVICE_CHANNEL_SWITCH)); + playAudioSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_AUDIO_PLAY)); + playResynthSwitchCB.setSelected( + parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_RESYNTH_PLAY)); + playPeaksSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_PLAY_PEAKS)); + loopSaveSwitchCB + .setSelected(parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_LOOP_SAVE)); + voicePlayerRepeatInput + .setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_PLAY_REPEAT)); + + pausePlaySwitchCB.setSelected( + parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_PAUSE_PLAY_SWITCH)); + voicePlayerDelayInput.setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_DELAY)); + voicePlayerLowThresholdInput + .setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_LOW_THRESHOLD)); + voicePlayerHighThresholdInput + .setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_HIGH_THRESHOLD)); + voicePlayerLogFactorInput + .setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_LOG_FACTOR)); + voicePlayerGlissandoRangeInput + .setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_GLISSANDO_RANGE)); + midiPlayLogSwitchCB.setSelected( + parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY_LOG_SWITCH)); + midiPlayVolumeSwitchCB.setSelected( + parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY_VOLUME_SWITCH)); + midiSynthTracksSwitchCB.setSelected(parameterManager + .getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_SYNTH_TRACKS_SWITCH)); + silentWriteSwitchCB.setSelected( + parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_SILENT_WRITE)); + trackWriteSwitchCB.setSelected( + parameterManager.getBooleanParameter(InstrumentParameterNames.ACTUATION_VOICE_TRACK_WRITE_SWITCH)); + streamSaveSwitchCB.setSelected( + parameterManager.getBooleanParameter(InstrumentParameterNames.PERCEPTION_HEARING_STREAM_SAVE_SWITCH)); + cortexShortCircuitSwitchCB.setSelected( + parameterManager.getBooleanParameter(InstrumentParameterNames.PERCEPTION_CORTEX_SHORT_CIRCUIT_SWITCH)); + streamIndexInput + .setText(parameterManager.getParameter(InstrumentParameterNames.PERCEPTION_HEARING_STREAM_SAVE_INDEX)); + playStartOffsetInput.setText( + parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY_START_OFFSET)); + playEndOffsetInput + .setText(parameterManager.getParameter(InstrumentParameterNames.ACTUATION_VOICE_MIDI_PLAY_END_OFFSET)); + int sampleRateParam = parameterManager + .getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_DEFAULT_SAMPLE_RATE); + int i = 0; + for (int sr : inputSampleRate) { + if (sr == sampleRateParam) { + inputSampleRateCombobox.setSelectedIndex(i); + break; + } + i++; + } + int fftParam = parameterManager.getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_DEFAULT_WINDOW); + i = 0; + for (int fws : fftWindowSizes) { + if (fws == fftParam) { + fftWindowSizeComboBox.setSelectedIndex(i); + break; + } + i++; + } + } + + public JPanel getContentPanel() { + return visorPanel; + } + + @Override + public void showException(InstrumentException exception) { + startListeningButton.setEnabled(false); + startFileProcessingButton.setEnabled(false); + stopListeningButton.setEnabled(false); + chooseFileButton.setEnabled(false); + frameNumberInput.setEnabled(false); + playAudioButton.setEnabled(false); + playStreamButton.setEnabled(false); + parametersButton.setEnabled(false); + updateViewButton.setEnabled(false); + synthButton.setEnabled(false); + resetSystemButton.setForeground(Color.RED); + updateStatusMessage("Instument System Error: " + exception.getMessage()); + } + + @Override + public void setPlayerState(boolean enabled) { + playStreamButton.setEnabled(enabled); + } + +} diff --git a/instrument-desktop/src/main/resources/instrument-client.properties b/instrument-desktop/src/main/resources/instrument-client.properties index 91357e4d..6f740eb4 100644 --- a/instrument-desktop/src/main/resources/instrument-client.properties +++ b/instrument-desktop/src/main/resources/instrument-client.properties @@ -1,12 +1,13 @@ -#Fri May 19 08:22:38 BST 2023 -perception.hearing.audioRange=30000 -perception.hearing.audioDefaultFile=chordC4-4-metro-12secs.wav -perception.hearing.audioFrameStoreDirectory=.instrument_audio/audio/framestore -perception.hearing.audioProjectDirectory=.instrument_audio/audio/project -perception.hearing.audioRecordDirectory=.instrument_audio/audio/recording -#perception.hearing.audioSourceDirectory=C:\\Users\\jim\\Desktop\\instrument_tests\\instrumnet\\060223 -perception.hearing.audioSourceDirectory=C:\\dev\\projects\\instrument\\instrument-core\\src\\main\\resources\\instrumentai -perception.hearing.tonemap.persistenceMode=2 -# actuation.voice.midiSoundFonts=FluidR3_GM.sf2 -storage.objectStore.basePath=user.home -actuation.voice.midiDevicePlaySwitch=true +#Fri May 19 08:22:38 BST 2023 +perception.hearing.audioRange=30000 +perception.hearing.audioDefaultFile=chordC4-4-metro-12secs.wav +perception.hearing.audioFrameStoreDirectory=.instrument_audio/audio/framestore +perception.hearing.audioProjectDirectory=.instrument_audio/audio/project +perception.hearing.audioRecordDirectory=.instrument_audio/audio/recording +#perception.hearing.audioSourceDirectory=C:\\Users\\jim\\Desktop\\instrument_tests\\instrumnet\\060223 +perception.hearing.audioSourceDirectory=C:\\dev\\projects\\instrument\\instrument-core\\src\\main\\resources\\instrumentai +perception.hearing.tonemap.persistenceMode=2 +# actuation.voice.midiSoundFonts=FluidR3_GM.sf2 +storage.objectStore.basePath=user.home +actuation.voice.midiDevicePlaySwitch=true +actuation.voice.midiDeviceChannelSwitch=false