Changed Group ALL sources action to Group ACTIVE sources

Manage mixing groups and clones on the way. This makes the action more flexible for the user, allowing to group only a selection.
This commit is contained in:
Bruno Herbelin
2022-07-06 23:34:36 +02:00
parent 93cb12be89
commit d77371912b
7 changed files with 53 additions and 15 deletions

View File

@@ -746,7 +746,7 @@ void Mixer::groupSelection()
} }
} }
void Mixer::groupAll() void Mixer::groupAll(bool only_active)
{ {
// obvious cancel // obvious cancel
if (session_->empty()) if (session_->empty())
@@ -759,16 +759,38 @@ void Mixer::groupAll()
// remember groups before emptying the session // remember groups before emptying the session
std::list<SourceList> allgroups = session_->getMixingGroups(); std::list<SourceList> allgroups = session_->getMixingGroups();
// empty the session (does not delete sources) // loop over sources from the current mixer session
for ( Source *s = session_->popSource(); s != nullptr; s = session_->popSource()) { for(auto it = session_->begin(); it != session_->end(); ) {
if ( sessiongroup->import(s) ) // if request for only active, take only active source
detach(s); // and if could import the source in the new session group
if ( ( !only_active || (*it)->active() ) && sessiongroup->import( *it ) ) {
// detatch the source from mixer
detach( *it );
// take out source from session and go to next (does not delete the source)
it = session_->removeSource( *it );
}
// otherwise just iterate (leave source in mixer)
else else
break; ++it;
} }
// successful creation of a session group
if (sessiongroup->session()->size() > 0) { if (sessiongroup->session()->size() > 0) {
// if a clone was left orphan in the mixer current session, take in in the group
for(auto it = session_->begin(); it != session_->end(); ) {
CloneSource *cs = dynamic_cast<CloneSource*>(*it);
if ( cs != nullptr && session_->find( cs->origin() ) == session_->end() && sessiongroup->import( *it ) ) {
// detatch the source from mixer
detach( *it );
// take out source from session and go to next (does not delete the source)
it = session_->removeSource( *it );
}
// otherwise just iterate (leave source in mixer)
else
++it;
}
// recreate groups in session group // recreate groups in session group
for (auto git = allgroups.begin(); git != allgroups.end(); ++git) for (auto git = allgroups.begin(); git != allgroups.end(); ++git)
sessiongroup->session()->link( *git ); sessiongroup->session()->link( *git );

View File

@@ -67,7 +67,7 @@ public:
// operations on selection // operations on selection
void deleteSelection (); void deleteSelection ();
void groupSelection (); void groupSelection ();
void groupAll (); void groupAll (bool only_active = false);
void ungroupAll (); void ungroupAll ();
void groupSession (); void groupSession ();

View File

@@ -305,8 +305,10 @@ SourceList::iterator Session::deleteSource(Source *s)
return its; return its;
} }
void Session::removeSource(Source *s) SourceList::iterator Session::removeSource(Source *s)
{ {
SourceList::iterator ret = sources_.end();
// lock before change // lock before change
access_.lock(); access_.lock();
@@ -320,11 +322,13 @@ void Session::removeSource(Source *s)
if (s->mixingGroup() != nullptr) if (s->mixingGroup() != nullptr)
s->mixingGroup()->detach(s); s->mixingGroup()->detach(s);
// erase the source from the update list & get next element // erase the source from the update list & get next element
sources_.erase(its); ret = sources_.erase(its);
} }
// unlock access // unlock access
access_.unlock(); access_.unlock();
return ret;
} }
Source *Session::popSource() Source *Session::popSource()

View File

@@ -57,7 +57,7 @@ public:
// remove this source from the session // remove this source from the session
// Does not delete the source // Does not delete the source
void removeSource(Source *s); SourceList::iterator removeSource (Source *s);
// get ptr to front most source and remove it from the session // get ptr to front most source and remove it from the session
// Does not delete the source // Does not delete the source

View File

@@ -45,6 +45,17 @@ SourceList playable_only (const SourceList &list)
return pl; return pl;
} }
bool notactive (const Source *s) { return !s->active(); }
SourceList active_only (const SourceList &list)
{
SourceList pl = list;
pl.remove_if(notactive);
return pl;
}
SourceList depth_sorted(const SourceList &list) SourceList depth_sorted(const SourceList &list)
{ {
SourceList sl = list; SourceList sl = list;

View File

@@ -12,6 +12,7 @@ typedef std::list<Source *> SourceList;
typedef std::list<SourceCore *> SourceCoreList; typedef std::list<SourceCore *> SourceCoreList;
SourceList playable_only (const SourceList &list); SourceList playable_only (const SourceList &list);
SourceList active_only (const SourceList &list);
SourceList depth_sorted (const SourceList &list); SourceList depth_sorted (const SourceList &list);
SourceList mixing_sorted (const SourceList &list, glm::vec2 center = glm::vec2(0.f, 0.f)); SourceList mixing_sorted (const SourceList &list, glm::vec2 center = glm::vec2(0.f, 0.f));
SourceList intersect (const SourceList &first, const SourceList &second); SourceList intersect (const SourceList &first, const SourceList &second);

View File

@@ -985,13 +985,13 @@ void UserInterface::showMenuFile()
// GROUP // GROUP
ImGui::Separator(); ImGui::Separator();
if (ImGuiToolkit::MenuItemIcon(11, 2, " Group all sources", false, Mixer::manager().numSource() > 0)) { if (ImGuiToolkit::MenuItemIcon(11, 2, " Group active sources", false, Mixer::manager().numSource() > 0)) {
// create a new group session with all sources // create a new group session with only active sources
Mixer::manager().groupAll(); Mixer::manager().groupAll( true );
// switch pannel to show first source (created) // switch pannel to show first source (created)
navigator.showPannelSource(0); navigator.showPannelSource(0);
} }
if (ImGuiToolkit::MenuItemIcon(7, 2, " Expand all groups", false, Mixer::manager().numSource() > 0)) { if (ImGuiToolkit::MenuItemIcon(7, 2, " Expand groups", false, Mixer::manager().numSource() > 0)) {
// create a new group session with all sources // create a new group session with all sources
Mixer::manager().ungroupAll(); Mixer::manager().ungroupAll();
} }