Skip to content

Commit

Permalink
Properly handle pausing anywhere in the UI.
Browse files Browse the repository at this point in the history
Fix for plugins initializing the portlist needlessly.
  • Loading branch information
gbevin committed Nov 12, 2023
1 parent 01be0c2 commit 8542f5e
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 53 deletions.
2 changes: 2 additions & 0 deletions Builds/MacOSX/showmidi.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
174103AD3F224D30061D8C33 /* JetBrainsMono-Italic.ttf */ /* JetBrainsMono-Italic.ttf */ = {isa = PBXFileReference; lastKnownFileType = file.ttf; name = "JetBrainsMono-Italic.ttf"; path = "../../Fonts/JetBrainsMono-Italic.ttf"; sourceTree = SOURCE_ROOT; };
17ACFE7C6558A3BFE6DE79C9 /* CoreMIDI.framework */ /* CoreMIDI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMIDI.framework; path = System/Library/Frameworks/CoreMIDI.framework; sourceTree = SDKROOT; };
18E89D52FCDF34385983843E /* AUv3 AppExtension */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = ShowMIDI.appex; sourceTree = BUILT_PRODUCTS_DIR; };
1E8AF652B5355FF40C9CC3C2 /* PauseManager.h */ /* PauseManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = PauseManager.h; path = ../../Source/PauseManager.h; sourceTree = SOURCE_ROOT; };
1F9AA665E4E0435365DA2D52 /* juce_data_structures */ /* juce_data_structures */ = {isa = PBXFileReference; lastKnownFileType = folder; name = juce_data_structures; path = ../../JuceLibraryCode/modules/juce_data_structures; sourceTree = SOURCE_ROOT; };
226AF0455917BA09A7EFD367 /* StandaloneWindow.h */ /* StandaloneWindow.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = StandaloneWindow.h; path = ../../Source/StandaloneWindow.h; sourceTree = SOURCE_ROOT; };
2343ECC7F67FA6AD9E72214D /* PluginProcessor.cpp */ /* PluginProcessor.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = PluginProcessor.cpp; path = ../../Source/PluginProcessor.cpp; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -548,6 +549,7 @@
BB0B90FF903B2C484336242E,
E071CD1AE979F36DF9BCBCCF,
88AAC6E05E409AD97864C094,
1E8AF652B5355FF40C9CC3C2,
5E8212E205DE721CE55589C7,
A7D51DA4FAC7916144DC9C37,
2343ECC7F67FA6AD9E72214D,
Expand Down
1 change: 1 addition & 0 deletions Builds/VisualStudio2022/ShowMIDI_SharedCode.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2429,6 +2429,7 @@
<ClInclude Include="..\..\Source\MidiDeviceInfoComparator.h"/>
<ClInclude Include="..\..\Source\MidiDevicesListener.h"/>
<ClInclude Include="..\..\Source\PaintedButton.h"/>
<ClInclude Include="..\..\Source\PauseManager.h"/>
<ClInclude Include="..\..\Source\PluginEditor.h"/>
<ClInclude Include="..\..\Source\PluginProcessor.h"/>
<ClInclude Include="..\..\Source\PluginSettings.h"/>
Expand Down
3 changes: 3 additions & 0 deletions Builds/VisualStudio2022/ShowMIDI_SharedCode.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -3108,6 +3108,9 @@
<ClInclude Include="..\..\Source\PaintedButton.h">
<Filter>ShowMIDI\Source</Filter>
</ClInclude>
<ClInclude Include="..\..\Source\PauseManager.h">
<Filter>ShowMIDI\Source</Filter>
</ClInclude>
<ClInclude Include="..\..\Source\PluginEditor.h">
<Filter>ShowMIDI\Source</Filter>
</ClInclude>
Expand Down
2 changes: 2 additions & 0 deletions Builds/iOS/ShowMIDI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
17ACFE7C6558A3BFE6DE79C9 /* CoreMIDI.framework */ /* CoreMIDI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMIDI.framework; path = System/Library/Frameworks/CoreMIDI.framework; sourceTree = SDKROOT; };
18E89D52FCDF34385983843E /* AUv3 AppExtension */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = ShowMIDI.appex; sourceTree = BUILT_PRODUCTS_DIR; };
1C6731403A5CDD50BA00A1BF /* Images.xcassets */ /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = ShowMIDI/Images.xcassets; sourceTree = SOURCE_ROOT; };
1E8AF652B5355FF40C9CC3C2 /* PauseManager.h */ /* PauseManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = PauseManager.h; path = ../../Source/PauseManager.h; sourceTree = SOURCE_ROOT; };
1F9AA665E4E0435365DA2D52 /* juce_data_structures */ /* juce_data_structures */ = {isa = PBXFileReference; lastKnownFileType = folder; name = juce_data_structures; path = ../../JuceLibraryCode/modules/juce_data_structures; sourceTree = SOURCE_ROOT; };
226AF0455917BA09A7EFD367 /* StandaloneWindow.h */ /* StandaloneWindow.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = StandaloneWindow.h; path = ../../Source/StandaloneWindow.h; sourceTree = SOURCE_ROOT; };
2343ECC7F67FA6AD9E72214D /* PluginProcessor.cpp */ /* PluginProcessor.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = PluginProcessor.cpp; path = ../../Source/PluginProcessor.cpp; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -390,6 +391,7 @@
BB0B90FF903B2C484336242E,
E071CD1AE979F36DF9BCBCCF,
88AAC6E05E409AD97864C094,
1E8AF652B5355FF40C9CC3C2,
5E8212E205DE721CE55589C7,
A7D51DA4FAC7916144DC9C37,
2343ECC7F67FA6AD9E72214D,
Expand Down
31 changes: 26 additions & 5 deletions Source/MainLayoutComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@

namespace showmidi
{
struct MainLayoutComponent::Pimpl : public SidebarListener
struct MainLayoutComponent::Pimpl : public SidebarListener, public KeyListener
{
static constexpr int DEFAULT_WINDOW_HEIGHT = 600;

Pimpl(MainLayoutComponent* owner, SettingsManager& manager, MainLayoutType type, Component* content) :
Pimpl(MainLayoutComponent* owner, SettingsManager& settings, PauseManager& pause, MainLayoutType type, Component* content) :
owner_(owner),
settingsManager_(manager),
settingsManager_(settings),
pauseManager_(pause),
layoutType_(type)
{
owner_->setWantsKeyboardFocus(true);
owner_->addKeyListener(this);

sidebar_.setBounds(0, 0, getSidebarWidth(), DEFAULT_WINDOW_HEIGHT);
owner_->addAndMakeVisible(sidebar_);

Expand All @@ -47,6 +51,22 @@ namespace showmidi
viewport_.setBounds(sidebar_.getWidth(), 0, default_width, DEFAULT_WINDOW_HEIGHT);
owner_->addAndMakeVisible(viewport_);
}

~Pimpl()
{
owner_->removeKeyListener(this);
}

bool keyPressed(const KeyPress& key, Component*) override
{
if (key.getKeyCode() == KeyPress::spaceKey)
{
pauseManager_.togglePaused();
return true;
}

return false;
}

bool isInterestedInFileDrag(const StringArray& files)
{
Expand Down Expand Up @@ -84,7 +104,7 @@ namespace showmidi
return sidebar_.getActiveWidth();
}

void sidebarChangedWidth()
void sidebarChangedWidth() override
{
if (layoutType_ == MainLayoutType::layoutStandalone)
{
Expand All @@ -94,6 +114,7 @@ namespace showmidi

MainLayoutComponent* const owner_;
SettingsManager& settingsManager_;
PauseManager& pauseManager_;
const MainLayoutType layoutType_;
SidebarComponent sidebar_ {
settingsManager_,
Expand All @@ -104,7 +125,7 @@ namespace showmidi
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Pimpl)
};

MainLayoutComponent::MainLayoutComponent(SettingsManager& m, MainLayoutType t, Component* c) : pimpl_(new Pimpl(this, m, t, c))
MainLayoutComponent::MainLayoutComponent(SettingsManager& s, PauseManager& p, MainLayoutType t, Component* c) : pimpl_(new Pimpl(this, s, p, t, c))
{
setSize(pimpl_->sidebar_.getWidth() + pimpl_->viewport_.getWidth(), Pimpl::DEFAULT_WINDOW_HEIGHT);
}
Expand Down
3 changes: 2 additions & 1 deletion Source/MainLayoutComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <JuceHeader.h>

#include "PauseManager.h"
#include "SettingsManager.h"

namespace showmidi
Expand All @@ -32,7 +33,7 @@ namespace showmidi
class MainLayoutComponent : public Component, public FileDragAndDropTarget
{
public:
MainLayoutComponent(SettingsManager&, MainLayoutType, Component*);
MainLayoutComponent(SettingsManager&, PauseManager&, MainLayoutType, Component*);
virtual ~MainLayoutComponent();

bool isInterestedInFileDrag(const StringArray&);
Expand Down
31 changes: 31 additions & 0 deletions Source/PauseManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* This file is part of ShowMIDI.
* Copyright (command) 2023 Uwyn LLC. https://www.uwyn.com
*
* ShowMIDI is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ShowMIDI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once

#include <JuceHeader.h>

namespace showmidi
{
class PauseManager
{
public:
virtual ~PauseManager() {};

virtual void togglePaused() = 0;
};
}
17 changes: 4 additions & 13 deletions Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

namespace showmidi
{
struct ShowMIDIPluginAudioProcessorEditor::Pimpl : public MultiTimer, public KeyListener, public SettingsManager
struct ShowMIDIPluginAudioProcessorEditor::Pimpl : public MultiTimer, public SettingsManager, public PauseManager
{
static constexpr int DEFAULT_EDITOR_HEIGHT = 600;

Expand Down Expand Up @@ -55,7 +55,6 @@ namespace showmidi

owner_->setSize(layout_.getWidth(), DEFAULT_EDITOR_HEIGHT);
owner_->setWantsKeyboardFocus(true);
owner_->addKeyListener(this);

// 30Hz
startTimer(RenderDevices, 1000 / 30);
Expand All @@ -65,8 +64,6 @@ namespace showmidi

~Pimpl()
{
owner_->removeKeyListener(this);

stopTimer(RenderDevices);
}

Expand All @@ -75,15 +72,9 @@ namespace showmidi
midiDevice_.handleIncomingMidiMessage(msg);
}

bool keyPressed(const KeyPress& key, Component*) override
void togglePaused() override
{
if (key.getKeyCode() == KeyPress::spaceKey)
{
setPaused(!paused_);
return true;
}

return false;
setPaused(!paused_);
}

void setPaused(bool paused)
Expand Down Expand Up @@ -160,7 +151,7 @@ namespace showmidi
ShowMIDIPluginAudioProcessor& audioProcessor_;

MidiDeviceComponent midiDevice_;
MainLayoutComponent layout_ { *this, MainLayoutType::layoutPlugin, &midiDevice_ };
MainLayoutComponent layout_ { *this, *this, MainLayoutType::layoutPlugin, &midiDevice_ };

MidiDevicesListeners midiDevicesListeners_;

Expand Down
40 changes: 25 additions & 15 deletions Source/SidebarComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ namespace showmidi
manager_(manager),
sidebarType_(type),
listener_(listener),
portList_(manager),
settings_(manager),
about_(manager.getSettings().getTheme())
{
Expand All @@ -57,16 +56,19 @@ namespace showmidi
owner_->addChildComponent(expandedButton_);
owner_->addAndMakeVisible(helpButton_);
owner_->addChildComponent(settingsButton_);

portViewport_.setScrollOnDragMode(Viewport::ScrollOnDragMode::all);
portViewport_.setScrollBarsShown(true, false);
portViewport_.setScrollBarThickness(Theme::SCROLLBAR_THICKNESS);
portViewport_.setViewedComponent(&portList_, false);
owner_->addChildComponent(portViewport_);


if (sidebarType_ == SidebarType::sidebarExpandable)
{
collapsedButton_.setVisible(true);

portList_ = std::make_unique<PortListComponent>(manager_);

portViewport_ = std::make_unique<Viewport>();
portViewport_->setScrollOnDragMode(Viewport::ScrollOnDragMode::all);
portViewport_->setScrollBarsShown(true, false);
portViewport_->setScrollBarThickness(Theme::SCROLLBAR_THICKNESS);
portViewport_->setViewedComponent(portList_.get(), false);
owner_->addChildComponent(portViewport_.get());
}
else
{
Expand All @@ -85,7 +87,10 @@ namespace showmidi
collapsedButton_.setVisible(false);
expandedButton_.setVisible(true);
settingsButton_.setVisible(true);
portViewport_.setVisible(true);
if (portViewport_.get())
{
portViewport_->setVisible(true);
}

settings_.setVisible(false);
about_.setVisible(false);
Expand All @@ -98,7 +103,10 @@ namespace showmidi
collapsedButton_.setVisible(true);
expandedButton_.setVisible(false);
settingsButton_.setVisible(false);
portViewport_.setVisible(false);
if (portViewport_.get())
{
portViewport_->setVisible(false);
}

settings_.setVisible(false);
about_.setVisible(false);
Expand Down Expand Up @@ -163,9 +171,11 @@ namespace showmidi
settingsButton_.setBoundsForTouch(owner_->getWidth() - expandedSvg_->getWidth() - X_SETTINGS, Y_SETTINGS,
settingsSvg_->getWidth(), settingsSvg_->getHeight());


portViewport_.setBounds(0, Y_PORTLIST, owner_->getWidth(), owner_->getHeight() - Y_PORTLIST - PORTLIST_BOTTOM_MARGIN);
portList_.setSize(owner_->getWidth() - portViewport_.getScrollBarThickness(), std::max(portViewport_.getHeight(), portList_.getVisibleHeight()));
if (portViewport_.get())
{
portViewport_->setBounds(0, Y_PORTLIST, owner_->getWidth(), owner_->getHeight() - Y_PORTLIST - PORTLIST_BOTTOM_MARGIN);
portList_->setSize(owner_->getWidth() - portViewport_->getScrollBarThickness(), std::max(portViewport_->getHeight(), portList_->getVisibleHeight()));
}
about_.setTopLeftPosition(owner_->getWidth() + X_SETTINGS, owner_->getHeight() - Y_SETTINGS - about_.getHeight());
settings_.setTopLeftPosition(owner_->getWidth() + X_SETTINGS, Y_SETTINGS);
}
Expand Down Expand Up @@ -196,8 +206,8 @@ namespace showmidi
PaintedButton expandedButton_;
PaintedButton helpButton_;
PaintedButton settingsButton_;
Viewport portViewport_;
PortListComponent portList_;
std::unique_ptr<Viewport> portViewport_;
std::unique_ptr<PortListComponent> portList_;
SettingsComponent settings_;
AboutComponent about_;

Expand Down
23 changes: 6 additions & 17 deletions Source/StandaloneDevicesComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace showmidi
{
struct StandaloneDevicesComponent::Pimpl : public MultiTimer, public KeyListener, public MidiDevicesListener
struct StandaloneDevicesComponent::Pimpl : public MultiTimer, public MidiDevicesListener
{
static constexpr int MIN_MIDI_DEVICES_AUTO_SHOWN = 1;
static constexpr int MAX_MIDI_DEVICES_AUTO_SHOWN = 6;
Expand All @@ -37,9 +37,6 @@ namespace showmidi

Pimpl(StandaloneDevicesComponent* owner) : owner_(owner)
{
owner_->setWantsKeyboardFocus(true);
owner_->addKeyListener(this);

SMApp.getMidiDevicesListeners().add(this);

refreshMidiDevices();
Expand All @@ -53,7 +50,6 @@ namespace showmidi
~Pimpl()
{
SMApp.getMidiDevicesListeners().remove(this);
owner_->removeKeyListener(this);

stopTimer(RenderDevices);

Expand Down Expand Up @@ -88,26 +84,19 @@ namespace showmidi
}
}

bool keyPressed(const KeyPress& key, Component*) override
void togglePaused()
{
if (key.getKeyCode() == KeyPress::spaceKey)
{
setPaused(!paused_);
return true;
}

return false;
setPaused(!paused_);
}

void setPaused(bool paused)
{
SMApp.setWindowTitle(String("ShowMIDI") + (paused ? " (paused)" : ""));
paused_ = paused;

ScopedLock g(midiDevicesLock_);
for (HashMap<const String, MidiDeviceComponent*>::Iterator i(midiDevices_); i.next();)
{
paused_ = paused;

i.getValue()->setPaused(paused);
}
}
Expand Down Expand Up @@ -201,8 +190,6 @@ namespace showmidi

if (devices_to_remove.size() > 0 || new_devices_preset)
{
setPaused(false);

owner_->removeAllChildren();

// remove the devices that disappeared
Expand All @@ -227,6 +214,7 @@ namespace showmidi
if (component == nullptr)
{
component = new MidiDeviceComponent(SMApp, info);
component->setPaused(paused_);
midiDevices_.set(info.identifier, component);
}

Expand Down Expand Up @@ -262,4 +250,5 @@ namespace showmidi
StandaloneDevicesComponent::~StandaloneDevicesComponent() = default;

void StandaloneDevicesComponent::paint(Graphics& g) { pimpl_->paint(g); }
void StandaloneDevicesComponent::togglePaused() { pimpl_->togglePaused(); }
}
Loading

0 comments on commit 8542f5e

Please sign in to comment.