Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ak5k committed Mar 31, 2023
1 parent b0d7f34 commit 0ff3ee9
Showing 1 changed file with 49 additions and 24 deletions.
73 changes: 49 additions & 24 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ MediaTrack* GetMixbus()

SetOnlyTrackSelected(res);
ReorderSelectedTracks(0, 0);
SetTrackSelected(res, false);

return res;
}
Expand Down Expand Up @@ -146,6 +147,7 @@ MediaTrack* GetSolobus()

SetOnlyTrackSelected(res);
ReorderSelectedTracks(0, 0);
SetTrackSelected(res, false);

return res;
}
Expand All @@ -155,6 +157,8 @@ void Organize()
auto master = GetMasterTrack(0);
auto mixbus = GetMixbus();
auto solobus = GetSolobus();
auto folderFound {false};

for (auto i = 0; i < GetNumTracks(); i++) {
auto tr = GetTrack(0, i);
if (HasSend(tr, master) && tr != mixbus && tr != solobus &&
Expand All @@ -168,6 +172,7 @@ void Organize()
}
auto parent = GetParentTrack(tr);
if (parent != nullptr) {
folderFound = true;
if (!HasSend(tr, parent)) {
CreateTrackSend(tr, parent);
}
Expand All @@ -183,13 +188,23 @@ void Organize()
SetMediaTrackInfo_Value(tr, "B_MAINSEND", 0);
}
}
SetMediaTrackInfo_Value(mixbus, "B_SOLO_DEFEAT", 1);
SetMediaTrackInfo_Value(solobus, "B_SOLO_DEFEAT", 1);

if (folderFound) {
ShowConsoleMsg(
"ReaSolotus: Folders not supported. Use sends instead. Setting "
"default solo mode to 'ignore-routing' highly recommended.\n");
}
}

void DoSolo(std::set<MediaTrack*>& queue)
{
PreventUIRefresh(1);
Undo_BeginBlock2(0);
Organize();
// Undo_BeginBlock2(0);
if (!queue.empty()) {
Organize();
}
auto solobus = GetSolobus();
auto mixbus = GetMixbus();
for (auto&& tr : queue) {
Expand All @@ -205,42 +220,50 @@ void DoSolo(std::set<MediaTrack*>& queue)
for (int i = 0; i < GetTrackNumSends(solobus, -1); i++) {
auto src = (MediaTrack*)(uintptr_t)
GetTrackSendInfo_Value(solobus, -1, i, "P_SRCTRACK");
if (!queue.contains(src)) {
SetTrackSendInfo_Value(solobus, -1, i, "B_MUTE", 1);
if (!queue.contains(src) && src != mixbus) {
auto isMuted =
(bool)GetTrackSendInfo_Value(solobus, -1, i, "B_MUTE");
if (!isMuted) {
SetTrackSendInfo_Value(solobus, -1, i, "B_MUTE", 1);
}
}
}

for (int i = 0; i < GetTrackNumSends(mixbus, 0); i++) {
auto dst = (MediaTrack*)(uintptr_t)
GetTrackSendInfo_Value(mixbus, 0, i, "P_DESTTRACK");
if (dst == solobus) {
SetTrackSendInfo_Value(
mixbus,
0,
i,
"B_MUTE",
AnyTrackSolo(0) ? 1 : 0);
auto isMuted = (bool)GetTrackSendInfo_Value(mixbus, 0, i, "B_MUTE");
if (isMuted && !AnyTrackSolo(0)) {
SetTrackSendInfo_Value(mixbus, 0, i, "B_MUTE", 0);
}
else if (!isMuted && AnyTrackSolo(0)) {
SetTrackSendInfo_Value(mixbus, 0, i, "B_MUTE", 1);
}
}
}

Undo_EndBlock2(0, "ReaSolotus", 0);
// Undo_EndBlock2(0, "ReaSolotus", 0);
PreventUIRefresh(-1);
}

void DoMute(MediaTrack* tr, bool mute)
{
PreventUIRefresh(1);
Undo_BeginBlock2(0);
(void)GetMixbus();
auto solobus = GetSolobus();
for (int i = 0; i < GetTrackNumSends(tr, 0); i++) {
auto dst = (MediaTrack*)(uintptr_t)
GetTrackSendInfo_Value(tr, 0, i, "P_DESTTRACK");
if (dst != solobus) {
SetTrackSendInfo_Value(tr, 0, i, "B_MUTE", mute ? 1 : 0);
auto isMuted = (bool)GetTrackSendInfo_Value(tr, 0, i, "B_MUTE");
if (!isMuted && mute) {
SetTrackSendInfo_Value(tr, 0, i, "B_MUTE", 1);
}
else if (isMuted && !mute) {
SetTrackSendInfo_Value(tr, 0, i, "B_MUTE", 0);
}
}
}

Undo_EndBlock2(0, "ReaSolotus: Mute", 0);
PreventUIRefresh(-1);
}

Expand Down Expand Up @@ -307,7 +330,6 @@ class ReaSolotus : public IReaperControlSurface {
}
void SetSurfaceSolo(MediaTrack* trackid, bool solo)
{
(void)solo;
// to avoid internal recursion
if (atomic_bool_lock == true) {
return;
Expand All @@ -323,18 +345,21 @@ class ReaSolotus : public IReaperControlSurface {
}

std::set<MediaTrack*> queue {};
for (int i = 0; i < GetNumTracks(); i++) {
auto tr = GetTrack(0, i);
int state {};
(void)GetTrackState(tr, &state);
if (state & 16) {
queue.insert(tr);
if (solo) {
for (int i = 0; i < GetNumTracks(); i++) {
auto tr = GetTrack(0, i);
int state {};
(void)GetTrackState(tr, &state);
if (state & 16) {
queue.insert(tr);
}
}
}

atomic_bool_lock = true;
DoSolo(queue);
atomic_bool_lock = false;
(void)solo;
}

void SetSurfaceMute(MediaTrack* trackid, bool mute)
Expand All @@ -344,7 +369,7 @@ class ReaSolotus : public IReaperControlSurface {
return;
}

std::scoped_lock lock(m);
// std::scoped_lock lock(m);
if (solotus_state == 0) {
return;
}
Expand Down

0 comments on commit 0ff3ee9

Please sign in to comment.