Skip to content

Commit

Permalink
Fix all CALF effects' port numbers, ranges and defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesLorenz committed Apr 2, 2018
1 parent 021e604 commit 62e1d8f
Showing 1 changed file with 209 additions and 7 deletions.
216 changes: 209 additions & 7 deletions src/core/DataFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -993,12 +993,22 @@ void iterate_ladspa_ports(QDomElement& effect, Ftor& ftor)
}
int num = parts[1].toInt();

// From Qt's docs of QDomNode:
// * copying a QDomNode is OK, they still have the same
// pointer to the "internal" QDomNodePrivate.
// * Also, they are using linked lists, which means
// deleting or appending QDomNode does not invalidate
// any other pointers.
// => Inside ftor, you can (and should) push back the
// QDomElements by value, not references
// => The loops below for adding and removing don't
// invalidate any other QDomElements
ftor(port, num, addList, removeList);
}

// Add ports marked for adding
for ( QDomElement e : addList )
{
puts("ADD");
ladspacontrol.appendChild( e );
}
// Remove ports marked for removal
Expand All @@ -1009,6 +1019,16 @@ void iterate_ladspa_ports(QDomElement& effect, Ftor& ftor)
}
}

// helper function if you need to print a QDomNode
QDebug operator<<(QDebug dbg, const QDomNode& node)
{
QString s;
QTextStream str(&s, QIODevice::WriteOnly);
node.save(str, 2);
dbg << qPrintable(s);
return dbg;
}

void DataFile::upgrade_1_3_0()
{
QDomNodeList list = elementsByTagName( "instrument" );
Expand Down Expand Up @@ -1051,6 +1071,7 @@ void DataFile::upgrade_1_3_0()
for( int k = 0; !attributes.item( k ).isNull(); ++k )
{
// Effect name changes

QDomElement attribute = attributes.item( k ).toElement();
if( attribute.attribute( "name" ) == "file" &&
( attribute.attribute( "value" ) == "calf" ||
Expand Down Expand Up @@ -1084,8 +1105,8 @@ void DataFile::upgrade_1_3_0()
attribute.setAttribute( "value", "MultibandLimiter" );
}


// Handle port changes

if( attribute.attribute( "name" ) == "plugin" &&
( attribute.attribute( "value" ) == "MultibandLimiter" ||
attribute.attribute( "value" ) == "MultibandCompressor" ||
Expand Down Expand Up @@ -1120,29 +1141,29 @@ void DataFile::upgrade_1_3_0()
case 16:
{
// old freq is now at port 25
QDomElement portCopy = createElement("port25");
QDomElement portCopy = createElement("port025");
portCopy.setAttribute("data", port.attribute("data"));
addList << portCopy;
// remove old freq port
removeList << port;
// set the "timing" port to choose port23+2=port25 (timing in Hz)
QDomElement timing = createElement("port22");
QDomElement timing = createElement("port022");
timing.setAttribute("data", 2);
addList << timing;
break;
}
// port 18 (modulation) => 17
case 17:
port.setTagName("port16");
port.setTagName("port016");
break;
case 18:
{
// leave port 18 (offsetr), but add port 17 (offsetl)
QDomElement offsetl = createElement("port17");
QDomElement offsetl = createElement("port017");
offsetl.setAttribute("data", .0f);
addList << offsetl;
// additional: bash port 21 to 1
QDomElement pulsewidth = createElement("port21");
QDomElement pulsewidth = createElement("port021");
pulsewidth.setAttribute("data", 1.f);
addList << pulsewidth;
break;
Expand All @@ -1154,6 +1175,187 @@ void DataFile::upgrade_1_3_0()
iterate_ladspa_ports(effect, fn);
}


if( attribute.attribute( "name" ) == "plugin" &&
( attribute.attribute( "value" ) == "VintageDelay" ) )
{
auto fn = [&](QDomElement& port, int num, QList<QDomElement>& addList, QList<QDomElement>& )
{
switch(num)
{
case 4:
{
// BPM is now port028
port.setTagName("port028");
// bash timing to BPM
QDomElement timing = createElement("port027");
timing.setAttribute("data", 0);
addList << timing;

// port 5 and 6 (in, out gain) need to be bashed to 1:
QDomElement input = createElement("port05");
input.setAttribute("data", 1.f);
addList << input;
QDomElement output = createElement("port06");
output.setAttribute("data", 1.f);
addList << output;

break;
}
default:
// all other ports increase by 10
QString name( "port0" );
name.append( QString::number( num + 10 ) );
port.setTagName( name );
}


};
iterate_ladspa_ports(effect, fn);
}

if( attribute.attribute( "name" ) == "plugin" &&
( ( attribute.attribute( "value" ) == "Equalizer5Band" )
|| ( attribute.attribute( "value" ) == "Equalizer8Band" )
|| ( attribute.attribute( "value" ) == "Equalizer12Band" ) ) )
{
// 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>& )
{
if(num == 4)
{
// don't modify port 4, but some other ones:
int zoom_port;
if(attribute.attribute( "value" ) == "Equalizer5Band")
zoom_port = 36;
else if(attribute.attribute( "value" ) == "Equalizer8Band")
zoom_port = 48;
else // 12 band
zoom_port = 64;
// bash zoom to 0.25
QString name( "port0" );
name.append( QString::number( zoom_port ) );
QDomElement timing = createElement(name);
timing.setAttribute("data", 0.25f);
addList << timing;
}
// the following code could be refactored, but I did careful code-reading
// to prevent copy-paste-errors
if(num == 18)
{
// 18 => 19
port.setTagName("port019");
// insert port 18 (q)
QDomElement q = createElement("port018");
q.setAttribute("data", 0.707f);
addList << q;
}
else if(num >= 19 && num <= 20)
{
// num += 1
QString name( "port0" );
name.append( QString::number( num + 1 ) );
port.setTagName( name );
}
else if(num == 21)
{
// 21 => 23
port.setTagName("port023");
// insert port 22 (q)
QDomElement q = createElement("port022");
q.setAttribute("data", 0.707f);
addList << q;
}
else if(num >= 22 && (num <= 23 || band5))
{
// num += 2
QString name( "port0" );
name.append( QString::number( num + 2 ) );
port.setTagName( name );
}
else if(num == 24 && !band5)
{
// 24 => 27
port.setTagName("port027");
// insert port 26 (q)
QDomElement q = createElement("port026");
q.setAttribute("data", 0.707f);
addList << q;
}
else if(num >= 25 && num <= 26 && !band5)
{
// num += 3
QString name( "port0" );
name.append( QString::number( num + 3 ) );
port.setTagName( name );
}
else if(num == 27 && !band5)
{
// 27 => 31
port.setTagName("port031");
// insert port 30 (q)
QDomElement q = createElement("port030");
q.setAttribute("data", 0.707f);
addList << q;
}
else if(num >= 28 && !band5)
{
// num += 4
QString name( "port0" );
name.append( QString::number( num + 4 ) );
port.setTagName( name );
}
};
iterate_ladspa_ports(effect, fn);
}

if( attribute.attribute( "name" ) == "plugin" &&
attribute.attribute( "value" ) == "Saturator" )
{
auto fn = [&](QDomElement& port, int num, QList<QDomElement>&, QList<QDomElement>& )
{
// These ports have been shifted a bit weird...
if( num == 7 )
{
port.setTagName("port015");
}
else if(num == 12)
{
port.setTagName("port016");
}
else if(num == 13)
{
port.setTagName("port017");
}
else if ( num >= 15 )
{
QString name( "port0" );
name.append( QString::number( num + 3 ) );
port.setTagName( name );
}
};
iterate_ladspa_ports(effect, fn);
}

if( attribute.attribute( "name" ) == "plugin" &&
attribute.attribute( "value" ) == "StereoTools" )
{
auto fn = [&](QDomElement& port, 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,
// and bash all new parameters (in this case, s.level and m.level) to
// their new defaults (both 1.0f in this case)

if( num == 23 || num == 25 )
{
port.setAttribute("data", 1.0f);
}
};
iterate_ladspa_ports(effect, fn);
}
}
}
}
Expand Down

0 comments on commit 62e1d8f

Please sign in to comment.