Skip to content

Commit

Permalink
fixup! Application::Instance: add Osc::ZoomDispatcher member
Browse files Browse the repository at this point in the history
  • Loading branch information
pierreguillot committed Dec 9, 2024
1 parent f8b548f commit 8d3fb0f
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 12 deletions.
6 changes: 3 additions & 3 deletions Source/Application/AnlApplicationInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ void Application::Instance::initialise(juce::String const& commandLine)
mDownloader = std::make_unique<Downloader>();
AppQuitIfInvalidPointer(mDownloader);

mOscZoomDispatcher = std::make_unique<Osc::ZoomDispatcher>(getOscSender());
AppQuitIfInvalidPointer(mOscZoomDispatcher);
mOscTrackDispatcher = std::make_unique<Osc::TrackDispatcher>(getOscSender());
AppQuitIfInvalidPointer(mOscTrackDispatcher);

mOscTransportDispatcher = std::make_unique<Osc::TransportDispatcher>(getOscSender());
AppQuitIfInvalidPointer(mOscTransportDispatcher);
Expand Down Expand Up @@ -318,7 +318,7 @@ void Application::Instance::shutdown()

mOscMouseDispatcher.reset();
mOscTransportDispatcher.reset();
mOscZoomDispatcher.reset();
mOscTrackDispatcher.reset();
mDownloader.reset();
mMainMenuModel.reset();
mWindow.reset();
Expand Down
2 changes: 1 addition & 1 deletion Source/Application/AnlApplicationInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace Application
std::unique_ptr<MainMenuModel> mMainMenuModel;
std::unique_ptr<CommandLine> mCommandLine;
std::unique_ptr<Downloader> mDownloader;
std::unique_ptr<Osc::ZoomDispatcher> mOscZoomDispatcher;
std::unique_ptr<Osc::TrackDispatcher> mOscTrackDispatcher;
std::unique_ptr<Osc::TransportDispatcher> mOscTransportDispatcher;
std::unique_ptr<Osc::MouseDispatcher> mOscMouseDispatcher;

Expand Down
65 changes: 61 additions & 4 deletions Source/Application/AnlApplicationOsc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ Application::Osc::SettingsPanel::~SettingsPanel()
setContent("", nullptr);
}

Application::Osc::ZoomDispatcher::ZoomDispatcher(Sender& sender)
Application::Osc::TrackDispatcher::TrackDispatcher(Sender& sender)
: mSender(sender)
, mLayoutNotifier(typeid(*this).name(), Instance::get().getDocumentAccessor(), [this]()
{
Expand Down Expand Up @@ -398,22 +398,77 @@ Application::Osc::ZoomDispatcher::ZoomDispatcher(Sender& sender)
}
};

mTrackListener.onAttrChanged = [this](Track::Accessor const& accessor, Track::AttrType attribute)
{
switch(attribute)
{
case Track::AttrType::identifier:
case Track::AttrType::name:
case Track::AttrType::file:
case Track::AttrType::results:
case Track::AttrType::edit:
case Track::AttrType::description:
case Track::AttrType::key:
case Track::AttrType::input:
case Track::AttrType::state:
case Track::AttrType::sampleRate:
case Track::AttrType::height:
case Track::AttrType::colours:
case Track::AttrType::font:
case Track::AttrType::lineWidth:
case Track::AttrType::unit:
case Track::AttrType::labelLayout:
case Track::AttrType::channelsLayout:
case Track::AttrType::showInGroup:
case Track::AttrType::sendViaOsc:
case Track::AttrType::zoomValueMode:
case Track::AttrType::zoomLogScale:
case Track::AttrType::zoomLink:
case Track::AttrType::zoomAcsr:
case Track::AttrType::graphics:
case Track::AttrType::warnings:
case Track::AttrType::processing:
case Track::AttrType::focused:
case Track::AttrType::grid:
case Track::AttrType::hasPluginColourMap:
break;
case Track::AttrType::extraThresholds:
{
juce::OSCMessage message("/" + accessor.getAttr<Track::AttrType::identifier>());
message.addString("thresholds");
auto const& extraThresholds = accessor.getAttr<Track::AttrType::extraThresholds>();
for(auto const& extraThreshold : extraThresholds)
{
if(extraThreshold.has_value())
{
message.addFloat32(extraThreshold.value());
}
}
if(!extraThresholds.empty())
{
mSender.send(message);
}
break;
};
}
};

synchosize(mSender.isConnected());
}

Application::Osc::ZoomDispatcher::~ZoomDispatcher()
Application::Osc::TrackDispatcher::~TrackDispatcher()
{
mSender.removeChangeListener(this);
synchosize(false);
}

void Application::Osc::ZoomDispatcher::changeListenerCallback([[maybe_unused]] juce::ChangeBroadcaster* source)
void Application::Osc::TrackDispatcher::changeListenerCallback([[maybe_unused]] juce::ChangeBroadcaster* source)
{
MiscWeakAssert(source == std::addressof(mSender));
synchosize(mSender.isConnected());
}

void Application::Osc::ZoomDispatcher::synchosize(bool connect)
void Application::Osc::TrackDispatcher::synchosize(bool connect)
{
auto& documentAcsr = Instance::get().getDocumentAccessor();
for(auto& trackAcsr : documentAcsr.getAcsrs<Document::AcsrType::tracks>())
Expand All @@ -423,6 +478,7 @@ void Application::Osc::ZoomDispatcher::synchosize(bool connect)
auto& binZoom = trackAcsr.get().getAcsr<Track::AcsrType::binZoom>();
if(trackConnected)
{
trackAcsr.get().addListener(mTrackListener, NotificationType::synchronous);
switch(Track::Tools::getFrameType(trackAcsr.get()).value_or(Track::FrameType::label))
{
case Track::FrameType::label:
Expand All @@ -449,6 +505,7 @@ void Application::Osc::ZoomDispatcher::synchosize(bool connect)
{
valueZoom.removeListener(mZoomListener);
binZoom.removeListener(mZoomListener);
trackAcsr.get().removeListener(mTrackListener);
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions Source/Application/AnlApplicationOsc.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ namespace Application
SettingsContent mContent;
};

class ZoomDispatcher
class TrackDispatcher
: public juce::ChangeListener
{
public:
ZoomDispatcher(Sender& sender);
~ZoomDispatcher() override;
TrackDispatcher(Sender& sender);
~TrackDispatcher() override;

private:
// juce::ChangeListener
Expand All @@ -117,9 +117,10 @@ namespace Application

Sender& mSender;
Document::LayoutNotifier mLayoutNotifier;
Track::Accessor::Listener mTrackListener{typeid(*this).name()};
Zoom::Accessor::Listener mZoomListener{typeid(*this).name()};

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ZoomDispatcher)
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TrackDispatcher)
};

class TransportDispatcher
Expand Down

0 comments on commit 8d3fb0f

Please sign in to comment.