diff --git a/src/core/channels/channelManager.cpp b/src/core/channels/channelManager.cpp index 31ed98cc6..424b411aa 100644 --- a/src/core/channels/channelManager.cpp +++ b/src/core/channels/channelManager.cpp @@ -237,7 +237,7 @@ void ChannelManager::deleteChannel(ID channelId) const Channel& ch = m_model.get().channels.get(channelId); const Wave* wave = ch.sampleChannel ? ch.sampleChannel->getWave() : nullptr; - m_model.get().channels.removeById(channelId); + m_model.get().channels.remove(channelId); m_model.swap(model::SwapType::HARD); if (wave != nullptr) diff --git a/src/core/model/channels.cpp b/src/core/model/channels.cpp index 1c58f7ed2..81dcbf6de 100644 --- a/src/core/model/channels.cpp +++ b/src/core/model/channels.cpp @@ -37,7 +37,18 @@ namespace giada::m::model { const Channel& Channels::get(ID id) const { - const Channel* out = find_(id); + const Channel* out = nullptr; + for (const Channel& ch : m_channels.getAll()) + { + if (ch.id == id) + out = &ch; + if (ch.type == ChannelType::GROUP) + { + const Channel* child = ch.groupChannel->channels->find(id); + if (child != nullptr) + out = child; + } + } assert(out != nullptr); return *out; } @@ -51,13 +62,25 @@ Channel& Channels::get(ID id) /* -------------------------------------------------------------------------- */ +std::vector& Channels::getAll() { return m_channels.getAll(); } +const std::vector& Channels::getAll() const { return m_channels.getAll(); } +Channel* Channels::find(ID id) { return m_channels.findById(id); } +const Channel* Channels::find(ID id) const { return m_channels.findById(id); } +Channel& Channels::add(Channel&& c) { return m_channels.add(std::move(c)); }; +Channel& Channels::getLast() { return m_channels.getLast(); } +void Channels::remove(ID id) { return m_channels.removeById(id); }; +bool Channels::anyOf(std::function f) const { return m_channels.anyOf(f); } +std::vector Channels::getIf(std::function f) { return m_channels.getIf(f); } + +/* -------------------------------------------------------------------------- */ + #ifdef G_DEBUG_MODE void Channels::debug() const { puts("model::channels"); - for (int i = 0; const Channel& c : getAll()) + for (int i = 0; const Channel& c : m_channels.getAll()) { fmt::print("\t{} - {}\n", i++, c.debug()); if (c.type == ChannelType::GROUP) @@ -74,22 +97,4 @@ void Channels::debug() const } #endif - -/* -------------------------------------------------------------------------- */ - -const Channel* Channels::find_(ID id) const -{ - for (const Channel& ch : getAll()) - { - if (ch.id == id) - return &ch; - if (ch.type == ChannelType::GROUP) - { - const Channel* child = ch.groupChannel->channels->findById(id); - if (child != nullptr) - return child; - } - } - return nullptr; -} } // namespace giada::m::model diff --git a/src/core/model/channels.h b/src/core/model/channels.h index cda2facad..a6f03fc06 100644 --- a/src/core/model/channels.h +++ b/src/core/model/channels.h @@ -33,7 +33,7 @@ namespace giada::m::model { -class Channels : public u::Container +class Channels { public: /* get @@ -42,12 +42,22 @@ class Channels : public u::Container& getAll(); + const std::vector& getAll() const; + Channel* find(ID); + const Channel* find(ID) const; + Channel& add(Channel&&); + Channel& getLast(); + void remove(ID); + bool anyOf(std::function) const; + std::vector getIf(std::function); + #ifdef G_DEBUG_MODE void debug() const; #endif private: - const Channel* find_(ID) const; + u::Container m_channels; }; } // namespace giada::m::model