Skip to content

Commit

Permalink
fix: Remove the unused debug code that had a bug (#18)
Browse files Browse the repository at this point in the history
#what Remove the debug code that I had in place during development that
showed last information played and stuff like that.
#why I probably won't use it again and can add it if needed. But mostly,
it had a concurrency bug. I was using a structure to store the currently
active notes and accessed it from another thread. No locks around it.
Sigh.

Co-authored-by: Mark Wilkins <markwilkins@github.com>
  • Loading branch information
markwilkins and Mark Wilkins committed Jul 4, 2023
1 parent 47e6515 commit 64c75bc
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 71 deletions.
50 changes: 1 addition & 49 deletions src/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,8 @@ MidiChordsAudioProcessorEditor::MidiChordsAudioProcessorEditor (MidiChordsAudioP
{
getLookAndFeel().setDefaultLookAndFeel(&lookAndFeel);
setResizable(true, true);
// To see the debug controls, make the height 400 here
setSize (1000, 210);


lastTimeStamp.setColour(juce::Label::ColourIds::textColourId, juce::Colours::black);
debugInfo1.setColour(juce::Label::ColourIds::textColourId, juce::Colours::black);
currentChords.setColour(juce::Label::ColourIds::textColourId, juce::Colours::black);

addAndMakeVisible(&lastTimeStamp);
addAndMakeVisible(&debugInfo1);
addAndMakeVisible(&currentChords);
addAndMakeVisible(&options);
addAndMakeVisible(&chordView);

Expand All @@ -45,22 +36,12 @@ MidiChordsAudioProcessorEditor::~MidiChordsAudioProcessorEditor()

void MidiChordsAudioProcessorEditor::timerCallback()
{
// some debug stuff that is hidden unless debugInfoSize is adjusted below
juce::String text;
std::unordered_set<juce::String>::iterator it;
text = "8:26 last: " + audioProcessor.lastNote + ": ";
for (it = audioProcessor.currentNotes.begin(); it != audioProcessor.currentNotes.end(); it++) {
text = text + " " + *it;
}

// The setDirty method for vst3 has this bit of code for setting dirty. I don't think it works, but leaving
// it here for further testing when I feel like it. If I figure out that it does work, then I need to set
// this when actual changes occur (e.g., when isViewUpToDate is set to false and for props like allowStateChange)
// this->audioProcessor.updateHostDisplay(AudioPluginInstance::ChangeDetails{}.withNonParameterStateChanged(true));

juce::String lastTime = std::to_string(audioProcessor.lastEventTime);
juce::String lastTimestampValue = std::to_string((int64)(audioProcessor.lastEventTimestamp));
lastTimeStamp.setText("lasttime: " + lastTimestampValue, juce::NotificationType::sendNotification);

// This is very cheesy - refresh the control settings in case the state has changed. I need to figure
// out the listener stuff better. But there are very few controls, so not expensive
Expand All @@ -77,28 +58,6 @@ void MidiChordsAudioProcessorEditor::timerCallback()
MidiStore *ms = audioProcessor.getMidiState();
ms->updateStaticViewIfOutOfDate();

debugInfo1.setText("visible chord count: " + std::to_string(ms->getViewWindowChordCount()), juce::NotificationType::sendNotification);

/*
std::string info = "";
std::vector<int64> eventTimes = ms->getEventTimes();
for (std::vector<int64>::iterator i = eventTimes.begin(); i != eventTimes.end(); ++i)
{
// info += std::to_string(*i) + ", ";
vector<int> itNotes = ms->getAllNotesOnAtTime(0, *i);
lastChord = cn.nameChord(itNotes);
if (lastChord != "")
{
double seconds = ms->getEventTimeInSeconds(*i);
ostringstream oss;
oss << info << lastChord << " (" << *i << ", " << seconds << "), ";
info = oss.str();
}
}
currentChords.setText("all chords: " + info, juce::NotificationType::sendNotification);
*/


}


Expand All @@ -117,13 +76,6 @@ void MidiChordsAudioProcessorEditor::paint (juce::Graphics& g)
void MidiChordsAudioProcessorEditor::resized()
{
// sets the position and size of the slider with arguments (x, y, width, height)
lastTimeStamp.setBounds(10, 10, 100, 30);
debugInfo1.setBounds(10, 40, getWidth() - 10, 30);
currentChords.setBounds(10, 70, getWidth() - 10, 60);
// Make this bigger to be able to see the debug info. Probably will remove this
// stuff at some point
int debugInfoSize = 0;

options.setBounds(0, getHeight() - 100, getWidth(), 100);
chordView.setBounds(0, debugInfoSize + 10, getWidth(), getHeight() - (debugInfoSize + 120));
chordView.setBounds(0, 10, getWidth(), getHeight() - 120);
}
5 changes: 0 additions & 5 deletions src/PluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ class MidiChordsAudioProcessorEditor : public juce::AudioProcessorEditor,
// access the processor object that created it.
MidiChordsAudioProcessor& audioProcessor;

// some debug info placeholders
juce::Label currentChords;
juce::Label lastTimeStamp;
juce::Label debugInfo1;

OptionsComponent options;
ChordView chordView;

Expand Down
12 changes: 0 additions & 12 deletions src/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,9 @@ void MidiChordsAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, j
auto message = metadata.getMessage();

int noteNumber = message.getNoteNumber();
lastNote = message.getMidiNoteName(noteNumber, true, false, 4);
auto messageEventTime = (int64)message.getTimeStamp() + posOfBlock.first;
if (message.isNoteOn())
{
this->currentNotes.insert(lastNote);
// mlwtbd: These two values were for helping me debug/understand. Probably will delete these two values.
this->lastEventTime = metadata.samplePosition;
this->lastEventTimestamp = messageEventTime;
// DBG("Note on: " + message.getDescription() + " at time " + std::to_string(lastEventTime));
midiState.addNoteEventAtTime(messageEventTime, noteNumber, true);
// mlwtbd - Store the current time in seconds that "might be" associated with this event.
// However this value is the current position of the playhead ... and we are offsetting the
Expand All @@ -183,12 +177,6 @@ void MidiChordsAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, j
}
if (message.isNoteOff())
{
// mlwtbd TODO: is the isMidiStop event included in this? This would let me know if this event is a "true"
// note off event versus one generated by stopping playback
std::unordered_set<juce::String>::iterator pos = currentNotes.find(lastNote);
if (pos != currentNotes.end()) {
currentNotes.erase(pos);
}
// DBG("Note off: " + message.getDescription());
midiState.addNoteEventAtTime(messageEventTime, noteNumber, false);
midiState.setEventTimeSeconds(messageEventTime, posOfBlock.second);
Expand Down
5 changes: 0 additions & 5 deletions src/PluginProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ class MidiChordsAudioProcessor : public juce::AudioProcessor
void getStateInformation (juce::MemoryBlock& destData) override;
void setStateInformation (const void* data, int sizeInBytes) override;

juce::String lastNote;
int lastEventTime = 0;
int64 lastEventTimestamp = 0;
std::unordered_set<juce::String> currentNotes;

MidiStore* getMidiState() { return &midiState; }

private:
Expand Down

0 comments on commit 64c75bc

Please sign in to comment.