Skip to content

Commit

Permalink
When copying modulation, dont make dups (surge-synthesizer#5951)
Browse files Browse the repository at this point in the history
Used to be we would always push back so if a modulator had
the same target you ended up in an inconsistent dup state.
Check for target already in list before adding now.

Closes surge-synthesizer#5770
  • Loading branch information
baconpaul authored Mar 7, 2022
1 parent e8fefc6 commit 58cfebc
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/common/SurgeStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,22 @@ void SurgeStorage::clipboard_paste(int type, int scene, int entry, modsources ms

modRoutingMutex.lock();

auto pushBackOrOverride = [this](std::vector<ModulationRouting> &modvec,
const ModulationRouting &m) {
bool wasDup = false;
for (auto &mt : modvec)
{
if (mt.destination_id == m.destination_id && mt.source_id == m.source_id &&
mt.source_scene == m.source_scene && mt.source_index == m.source_index)
{
mt.depth = m.depth;
wasDup = true;
}
}
if (!wasDup)
modvec.push_back(m);
};

{
for (int i = start; i < n; i++)
{
Expand Down Expand Up @@ -1531,7 +1547,7 @@ void SurgeStorage::clipboard_paste(int type, int scene, int entry, modsources ms
m.source_scene = scene;
m.destination_id =
clipboard_modulation_voice[i].destination_id + id - n_global_params;
getPatch().scene[scene].modulation_voice.push_back(m);
pushBackOrOverride(getPatch().scene[scene].modulation_voice, m);
}

n = clipboard_modulation_scene.size();
Expand All @@ -1544,7 +1560,7 @@ void SurgeStorage::clipboard_paste(int type, int scene, int entry, modsources ms
m.source_scene = scene;
m.destination_id =
clipboard_modulation_scene[i].destination_id + id - n_global_params;
getPatch().scene[scene].modulation_scene.push_back(m);
pushBackOrOverride(getPatch().scene[scene].modulation_scene, m);
}
}

Expand Down Expand Up @@ -1596,11 +1612,11 @@ void SurgeStorage::clipboard_paste(int type, int scene, int entry, modsources ms
{
if (isScenelevel((modsources)m.source_id))
{
getPatch().scene[scene].modulation_scene.push_back(m);
pushBackOrOverride(getPatch().scene[scene].modulation_scene, m);
}
else
{
getPatch().scene[scene].modulation_voice.push_back(m);
pushBackOrOverride(getPatch().scene[scene].modulation_voice, m);
}
}
}
Expand All @@ -1620,11 +1636,11 @@ void SurgeStorage::clipboard_paste(int type, int scene, int entry, modsources ms
{
if (isScenelevel((modsources)m.source_id))
{
getPatch().scene[scene].modulation_scene.push_back(m);
pushBackOrOverride(getPatch().scene[scene].modulation_scene, m);
}
else
{
getPatch().scene[scene].modulation_voice.push_back(m);
pushBackOrOverride(getPatch().scene[scene].modulation_voice, m);
}
}
}
Expand All @@ -1641,7 +1657,7 @@ void SurgeStorage::clipboard_paste(int type, int scene, int entry, modsources ms

if (isValid(m.destination_id, (modsources)m.source_id))
{
getPatch().modulation_global.push_back(m);
pushBackOrOverride(getPatch().modulation_global, m);
}
}
}
Expand All @@ -1660,7 +1676,7 @@ void SurgeStorage::clipboard_paste(int type, int scene, int entry, modsources ms
m.source_index = clipboard_modulation_voice[i].source_index;
m.depth = clipboard_modulation_voice[i].depth;
m.destination_id = clipboard_modulation_voice[i].destination_id;
getPatch().scene[scene].modulation_voice.push_back(m);
pushBackOrOverride(getPatch().scene[scene].modulation_voice, m);
}

n = clipboard_modulation_scene.size();
Expand All @@ -1671,7 +1687,7 @@ void SurgeStorage::clipboard_paste(int type, int scene, int entry, modsources ms
m.source_index = clipboard_modulation_scene[i].source_index;
m.depth = clipboard_modulation_scene[i].depth;
m.destination_id = clipboard_modulation_scene[i].destination_id;
getPatch().scene[scene].modulation_scene.push_back(m);
pushBackOrOverride(getPatch().scene[scene].modulation_scene, m);
}
}
}
Expand Down

0 comments on commit 58cfebc

Please sign in to comment.