Skip to content

Commit

Permalink
CAPS: DataFile: Map some ports, incomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesLorenz committed Sep 12, 2020
1 parent a0246f3 commit e1a5cc2
Showing 1 changed file with 152 additions and 20 deletions.
172 changes: 152 additions & 20 deletions src/core/DataFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,9 @@ void iterate_ladspa_ports(QDomElement& effect, Ftor& ftor)
{
continue;
}
int num = parts[1].toInt();

int proc = parts[1].left(1).toInt(); // = left or right
int num = parts[1].mid(1).toInt();

// From Qt's docs of QDomNode:
// * copying a QDomNode is OK, they still have the same
Expand All @@ -976,7 +978,7 @@ void iterate_ladspa_ports(QDomElement& effect, Ftor& ftor)
// QDomElements by value, not references
// => The loops below for adding and removing don't
// invalidate any other QDomElements
ftor(port, num, addList, removeList);
ftor(port, proc, num, addList, removeList);
}

// Add ports marked for adding
Expand Down Expand Up @@ -1030,6 +1032,9 @@ void DataFile::upgrade_1_3_0()
}
}

/*
* fix CALF and CAPS effects
*/
list = elementsByTagName( "effect" );
for( int i = 0; !list.item( i ).isNull(); ++i )
{
Expand All @@ -1043,8 +1048,9 @@ void DataFile::upgrade_1_3_0()
QDomNodeList attributes = key.elementsByTagName( "attribute" );
for( int k = 0; !attributes.item( k ).isNull(); ++k )
{
// Effect name changes

/*
* CALF effect name changes
*/
QDomElement attribute = attributes.item( k ).toElement();
if( attribute.attribute( "name" ) == "file" &&
( attribute.attribute( "value" ) == "calf" ||
Expand Down Expand Up @@ -1078,14 +1084,15 @@ void DataFile::upgrade_1_3_0()
attribute.setAttribute( "value", "MultibandLimiter" );
}

// Handle port changes

/*
* CALF port changes
*/
if( attribute.attribute( "name" ) == "plugin" &&
( attribute.attribute( "value" ) == "MultibandLimiter" ||
attribute.attribute( "value" ) == "MultibandCompressor" ||
attribute.attribute( "value" ) == "MultibandGate" ) )
{
auto fn = [&](QDomElement& port, int num, QList<QDomElement>&, QList<QDomElement>& removeList)
auto fn = [&](QDomElement& port, int, int num, QList<QDomElement>&, QList<QDomElement>& removeList)
{
// Mark ports for removal
if ( num >= 18 && num <= 23 )
Expand All @@ -1107,7 +1114,7 @@ void DataFile::upgrade_1_3_0()
if( attribute.attribute( "name" ) == "plugin" &&
( attribute.attribute( "value" ) == "Pulsator" ) )
{
auto fn = [&](QDomElement& port, int num, QList<QDomElement>& addList, QList<QDomElement>& removeList)
auto fn = [&](QDomElement& port, int, int num, QList<QDomElement>& addList, QList<QDomElement>& removeList)
{
switch(num)
{
Expand Down Expand Up @@ -1152,7 +1159,7 @@ void DataFile::upgrade_1_3_0()
if( attribute.attribute( "name" ) == "plugin" &&
( attribute.attribute( "value" ) == "VintageDelay" ) )
{
auto fn = [&](QDomElement& port, int num, QList<QDomElement>& addList, QList<QDomElement>& )
auto fn = [&](QDomElement& port, int, int num, QList<QDomElement>& addList, QList<QDomElement>& )
{
switch(num)
{
Expand Down Expand Up @@ -1195,7 +1202,7 @@ void DataFile::upgrade_1_3_0()
// NBand equalizers got 4 q nobs inserted. We need to shift everything else...
// HOWEVER: 5 band eq has only 2 q nobs inserted (no LS/HS filters)
bool band5 = ( attribute.attribute( "value" ) == "Equalizer5Band" );
auto fn = [&](QDomElement& port, int num, QList<QDomElement>& addList, QList<QDomElement>& )
auto fn = [&](QDomElement& port, int, int num, QList<QDomElement>& addList, QList<QDomElement>& )
{
if(num == 4)
{
Expand Down Expand Up @@ -1287,7 +1294,7 @@ void DataFile::upgrade_1_3_0()
if( attribute.attribute( "name" ) == "plugin" &&
attribute.attribute( "value" ) == "Saturator" )
{
auto fn = [&](QDomElement& port, int num, QList<QDomElement>&, QList<QDomElement>& )
auto fn = [&](QDomElement& port, int, int num, QList<QDomElement>&, QList<QDomElement>& )
{
// These ports have been shifted a bit weird...
if( num == 7 )
Expand Down Expand Up @@ -1315,7 +1322,7 @@ void DataFile::upgrade_1_3_0()
if( attribute.attribute( "name" ) == "plugin" &&
attribute.attribute( "value" ) == "StereoTools" )
{
auto fn = [&](QDomElement& port, int num, QList<QDomElement>&, QList<QDomElement>& )
auto fn = [&](QDomElement& port, int, int num, QList<QDomElement>&, QList<QDomElement>& )
{
// This effect can not be back-ported due to bugs in the old version,
// or due to different behaviour. We thus port all parameters we can,
Expand All @@ -1329,9 +1336,87 @@ void DataFile::upgrade_1_3_0()
};
iterate_ladspa_ports(effect, fn);
}
// Upgrade C* Eq to C* Eq10

/*
* CAPS port changes
*/

/*
how to write this
1 - open both LMMS versions, and check visually where ports moved
2 - compare savefiles to find out how the indexes of the movements are
3 - write down the port movements here (port.setTagName...)
4 - all port numbers that are not source or dest of a move and exist in both old and new must be bashed to the new defaults
5 - fine tuning on individual parameters (e.g. if their scale changed)
*/
auto new_port_name = [](int proc, int new_num) -> QString {
return "port" + QString::number(proc) + QString::number(new_num);
};

if( attribute.attribute( "name" ) == "plugin" &&
attribute.attribute( "value" ) == "AmpVTS" )
{
auto fn = [&](QDomElement& port, int proc, int num, QList<QDomElement>&, QList<QDomElement>&)
{
if(num == 2)
{
port.setTagName(new_port_name(proc, 1));
}
else if(num == 3 || num == 4 || num == 5)
{
port.setTagName(new_port_name(proc, 2 + num));
}
};
iterate_ladspa_ports(effect, fn);
}

if( attribute.attribute( "name" ) == "plugin" &&
attribute.attribute( "value" ) == "AutoWah" )
{
attribute.setAttribute( "value", "AutoFilter" );
auto fn = [&](QDomElement& port, int proc, int num, QList<QDomElement>&, QList<QDomElement>&)
{
if(num == 1 || num == 2 || num == 3)
{
port.setTagName(new_port_name(proc, 1 + num));
}
};
iterate_ladspa_ports(effect, fn);
}

if( attribute.attribute( "name" ) == "plugin" &&
attribute.attribute( "value" ) == "ChorusI" )
{
auto fn = [&](QDomElement& port, int proc, int num, QList<QDomElement>&, QList<QDomElement>&)
{
port.setTagName(new_port_name(proc, num - 1));
};
iterate_ladspa_ports(effect, fn);
}

if( attribute.attribute( "name" ) == "plugin" &&
attribute.attribute( "value" ) == "Clip" )
{
attribute.setAttribute( "value", "Saturate" );
// FIXME: Ports conveniently map, but the volume is too quiet
}

if( attribute.attribute( "name" ) == "plugin" &&
attribute.attribute( "value" ) == "Compress" )
{
// TODO

// 1->6
// 2->3??? (or bash)
// 3 -> 4
// 4 -> 5
// 5-> 2
// 6 -> bash

}

if( attribute.attribute( "name" ) == "plugin" &&
attribute.attribute( "value" ) == "Eq" )
attribute.attribute( "value" ) == "Eq" )
{
attribute.setAttribute( "value", "Eq10" );
// Head back up the DOM to upgrade ports
Expand Down Expand Up @@ -1385,11 +1470,53 @@ void DataFile::upgrade_1_3_0()
}
}
}
// Upgrade C* Plate2x2 to PlateX2

if( attribute.attribute( "name" ) == "plugin" &&
attribute.attribute( "value" ) == "Plate2x2" )
attribute.attribute( "value" ) == "Eq2x2" )
{
attribute.setAttribute( "value", "Eq10X2" );
auto fn = [&](QDomElement& port, int proc, int num, QList<QDomElement>&, QList<QDomElement>&)
{
port.setTagName(new_port_name(proc, num - 2));
};
iterate_ladspa_ports(effect, fn);
}

if( attribute.attribute( "name" ) == "Narrower" &&
attribute.attribute( "value" ) == "Narrower" )
{
attribute.setAttribute( "value", "Eq10X2" );
auto fn = [&](QDomElement& port, int proc, int num, QList<QDomElement>&, QList<QDomElement>&)
{
if(num == 2) {
port.setTagName(new_port_name(proc, 1));
}
};
iterate_ladspa_ports(effect, fn);
}

if( attribute.attribute( "name" ) == "PhaserII" &&
attribute.attribute( "value" ) == "PhaserII" )
{
auto fn = [&](QDomElement& port, int proc, int num, QList<QDomElement>&, QList<QDomElement>&)
{
if(num == 1) {
port.setTagName(new_port_name(proc, 0));
}
else if(num == 4) {
assert(port.hasAttribute("data"));
// feedback is now multiplied by 0.9f => change scale
port.setAttribute("data", port.attribute("data").toFloat() / 0.9f);
}
};
iterate_ladspa_ports(effect, fn);
}

if( attribute.attribute( "name" ) == "plugin" &&
attribute.attribute( "value" ) == "Plate2x2" )
{
attribute.setAttribute( "value", "PlateX2" );

// Head back up the DOM to upgrade ports
QDomNodeList ladspacontrols = effect.elementsByTagName( "ladspacontrols" );
for( int m = 0; !ladspacontrols.item( m ).isNull(); ++m )
Expand All @@ -1414,12 +1541,17 @@ void DataFile::upgrade_1_3_0()
}
}
}
// Upgrade C* Clip to C* Saturate

if( attribute.attribute( "name" ) == "plugin" &&
attribute.attribute( "value" ) == "Clip" )
attribute.attribute( "value" ) == "ToneStack" )
{
attribute.setAttribute( "value", "Saturate" );
// FIXME: Ports conveniently map, but the volume is too quiet
auto fn = [&](QDomElement& port, int proc, int num, QList<QDomElement>&, QList<QDomElement>& )
{
// all ports move down by one
QString new_number = QString::number(proc) + QString::number(num - 1);
port.setTagName( "port" + new_number );
};
iterate_ladspa_ports(effect, fn);
}
}
}
Expand Down

0 comments on commit e1a5cc2

Please sign in to comment.