diff --git a/src/effects/backends/effectmanifestparameter.h b/src/effects/backends/effectmanifestparameter.h index 40f9ac007d11..8c740a994709 100644 --- a/src/effects/backends/effectmanifestparameter.h +++ b/src/effects/backends/effectmanifestparameter.h @@ -67,60 +67,41 @@ class EffectManifestParameter { Time, // units? }; - static UnitsHint lv2UnitToUnitsHint(const QString& lv2Unit) { - // Add custom LV2 units here (with correct case) and also - // in unitsHintToString() - if (lv2Unit == QLatin1String("bar")) { - return UnitsHint::Bar; - } else if (lv2Unit == QLatin1String("beat")) { - return UnitsHint::Beat; - } else if (lv2Unit == QLatin1String("bpm")) { - return UnitsHint::BPM; - } else if (lv2Unit == QLatin1String("cent")) { - return UnitsHint::Cent; - } else if (lv2Unit == QLatin1String("cm")) { - return UnitsHint::Centimetre; - } else if (lv2Unit == QLatin1String("coef")) { - return UnitsHint::Coefficient; - } else if (lv2Unit == QLatin1String("db")) { - return UnitsHint::Decibel; - } else if (lv2Unit == QLatin1String("degree")) { - return UnitsHint::Degree; - } else if (lv2Unit == QLatin1String("frame")) { - return UnitsHint::Frame; - } else if (lv2Unit == QLatin1String("hz")) { - return UnitsHint::Hertz; - } else if (lv2Unit == QLatin1String("inch")) { - return UnitsHint::Inch; - } else if (lv2Unit == QLatin1String("khz")) { - return UnitsHint::KiloHertz; - } else if (lv2Unit == QLatin1String("km")) { - return UnitsHint::Kilometer; - } else if (lv2Unit == QLatin1String("m")) { - return UnitsHint::Meter; - } else if (lv2Unit == QLatin1String("mhz")) { - return UnitsHint::MegaHertz; - } else if (lv2Unit == QLatin1String("midiNote")) { - return UnitsHint::Midinote; - } else if (lv2Unit == QLatin1String("mile")) { - return UnitsHint::Mile; - } else if (lv2Unit == QLatin1String("min")) { - return UnitsHint::Minute; - } else if (lv2Unit == QLatin1String("mm")) { - return UnitsHint::Millmeter; - } else if (lv2Unit == QLatin1String("ms")) { - return UnitsHint::Millisecond; - } else if (lv2Unit == QLatin1String("oct")) { - return UnitsHint::Octave; - } else if (lv2Unit == QLatin1String("pc")) { - return UnitsHint::Percentage; - } else if (lv2Unit == QLatin1String("s")) { - return UnitsHint::Seconds; - } else if (lv2Unit == QLatin1String("semitone12TET")) { - return UnitsHint::Semitone12tet; - } else { + const QHash lv2UnitToUnitsHintHash{ + // Add custom LV2 units here (with correct case) and also + // in unitsHintStringHash() + {QString("bar"), UnitsHint::Bar}, + {QString("beat"), UnitsHint::Beat}, + {QString("bpm"), UnitsHint::BPM}, + {QString("cent"), UnitsHint::Cent}, + {QString("cm"), UnitsHint::Centimetre}, + {QString("coef"), UnitsHint::Coefficient}, + {QString("db"), UnitsHint::Decibel}, + {QString("degree"), UnitsHint::Degree}, + {QString("frame"), UnitsHint::Frame}, + {QString("hz"), UnitsHint::Hertz}, + {QString("inch"), UnitsHint::Inch}, + {QString("khz"), UnitsHint::KiloHertz}, + {QString("km"), UnitsHint::Kilometer}, + {QString("m"), UnitsHint::Meter}, + {QString("mhz"), UnitsHint::MegaHertz}, + {QString("midiNote"), UnitsHint::Midinote}, + {QString("mile"), UnitsHint::Mile}, + {QString("min"), UnitsHint::Minute}, + {QString("mm"), UnitsHint::Millmeter}, + {QString("ms"), UnitsHint::Millisecond}, + {QString("oct"), UnitsHint::Octave}, + {QString("pc"), UnitsHint::Percentage}, + {QString("s"), UnitsHint::Seconds}, + {QString("semitone12TET"), UnitsHint::Semitone12tet}}; + + UnitsHint lv2UnitToUnitsHint(const QString& lv2) { + QHash::const_iterator uHintIt = + lv2UnitToUnitsHintHash.find(lv2); + if (uHintIt == lv2UnitToUnitsHintHash.constEnd()) { return UnitsHint::Unknown; } + return uHintIt.value(); } const QHash unitsHintStringHash{ diff --git a/src/effects/backends/lv2/lv2manifest.cpp b/src/effects/backends/lv2/lv2manifest.cpp index bccf96b6aabb..0b8fc8b87eaa 100644 --- a/src/effects/backends/lv2/lv2manifest.cpp +++ b/src/effects/backends/lv2/lv2manifest.cpp @@ -83,7 +83,7 @@ LV2Manifest::LV2Manifest(LilvWorld* world, QString unitStr = lilv_node_as_uri(unit); // that starts with the 'units' prefix, isolate the identifier if (unitStr.startsWith(lilv_node_as_string(properties["unit_prefix"]))) { - unitsHint = EffectManifestParameter::lv2UnitToUnitsHint( + unitsHint = param->lv2UnitToUnitsHint( unitStr.remove(lilv_node_as_string(properties["unit_prefix"]))); } } else { // Try to extract the custom unit symbol string @@ -93,7 +93,7 @@ LV2Manifest::LV2Manifest(LilvWorld* world, // Accepted custom units needs to be 'whitelisted' in // EffectManifestParameter::lv2UnitToUnitsHint and added to // EffectManifestParameter::unitsHintStringHash - unitsHint = EffectManifestParameter::lv2UnitToUnitsHint( + unitsHint = param->lv2UnitToUnitsHint( lilv_node_as_string(customUnit)); if (lv2ParamDebug && unitsHint == EffectManifestParameter::UnitsHint::Unknown &&