@@ -80,11 +80,12 @@ BitInvader::BitInvader(InstrumentTrack* instrumentTrack)
8080 , m_interpolation(false , this , tr(" Interpolation" ))
8181 , m_normalizeMode(this , tr(" Normalize" ))
8282{
83- m_normalizeMode.addItem (" Off" );
84- m_normalizeMode.addItem (" Full" );
85- m_normalizeMode.addItem (" Length only" );
86- m_normalizeMode.addItem (" Legacy" );
87- m_normalizeMode.setValue (m_normalizeMode.findText (" Length only" ));
83+ // The order these items are added must correspond to the modes in BitInvader::NormalizeMode
84+ m_normalizeMode.addItem (tr (" Off" )); // NormalizeMode::Off
85+ m_normalizeMode.addItem (tr (" Full" )); // NormalizeMode::Full
86+ m_normalizeMode.addItem (tr (" Length only" )); // NormalizeMode::LengthOnly
87+ m_normalizeMode.addItem (tr (" Legacy" )); // NormalizeMode::Legacy
88+ m_normalizeMode.setValue (static_cast <int >(NormalizeMode::LengthOnly));
8889
8990 m_graph.setWaveToSine ();
9091 lengthChanged ();
@@ -131,9 +132,9 @@ void BitInvader::loadSettings(const QDomElement& el)
131132 m_interpolation.loadSettings (el, " interpolation" );
132133 m_normalizeMode.loadSettings (el, " normalize" );
133134 // If normalization was enabled on an old preset, change it to "Legacy" normalization mode
134- if (el.attribute (" version" ) == " 0.1" )
135+ if (el.attribute (" version" ) == " 0.1" ) // TODO: Make new version 1 instead, cast to int and compare < 1
135136 {
136- m_normalizeMode.setValue (m_normalizeMode.value () * m_normalizeMode. findText ( " Legacy" ) );
137+ m_normalizeMode.setValue (m_normalizeMode.value () * static_cast < int >(NormalizeMode:: Legacy);
137138 }
138139}
139140
@@ -151,19 +152,21 @@ void BitInvader::lengthChanged()
151152
152153void BitInvader::normalize ()
153154{
154- if (m_normalizeMode.value () == m_normalizeMode. findText ( " Off" ))
155+ if (m_normalizeMode.value () == static_cast < int >(NormalizeMode:: Off))
155156 {
156157 m_normalizeFactor = 1 .f ;
157158 m_normalizeOffset = 0 .f ;
158159 return ;
159160 }
160161
161- const auto len = m_normalizeMode.value () == m_normalizeMode.findText (" Length only" )
162- ? static_cast <std::size_t >(m_sampleLength.value ())
163- : wavetableSize;
164- const auto samples = std::span<const float >{ m_graph.samples (), len };
162+ const auto samples = std::span<const float >{
163+ m_graph.samples (),
164+ m_normalizeMode.value () == static_cast <int >(NormalizeMode::LengthOnly)
165+ ? static_cast <std::size_t >(m_sampleLength.value ())
166+ : wavetableSize
167+ };
165168
166- if (m_normalizeMode.value () == m_normalizeMode. findText ( " Legacy" ))
169+ if (m_normalizeMode.value () == static_cast < int >(NormalizeMode:: Legacy))
167170 {
168171 m_normalizeOffset = 0 .f ;
169172 m_normalizeFactor = 1 .f / std::max_element (samples.begin (), samples.end (), [](auto a, auto b){ return std::abs (a) < std::abs (b); })[0 ];
@@ -318,12 +321,12 @@ BitInvaderView::BitInvaderView(Instrument* instrument, QWidget* parent)
318321 auto normalizeLabel = new QLabel (tr (" Normalization:" ), this );
319322 normalizeLabel->setFont (adjustedToPixelSize (normalizeLabel->font (), DEFAULT_FONT_SIZE));
320323 // FIXME: Evil awful terrible layout. This should be fine for now,
321- // since a full UI overhaul for Bit Invader is planned.
324+ // since a full UI overhaul for Bit Invader is planned in #8122 .
322325 auto normalizeLayout = new QGridLayout (this );
323326 normalizeLayout->setContentsMargins (6 , 6 , 6 , 6 );
324327 normalizeLayout->setVerticalSpacing (1 );
325328 normalizeLayout->setAlignment (Qt::AlignBottom);
326- normalizeLayout->addItem (new QSpacerItem (250 - 131 , 1 ), 0 , 0 ); // Do NOT ever do this LMAO
329+ normalizeLayout->addItem (new QSpacerItem (250 - 131 , 1 ), 0 , 0 ); // HACK: Do NOT ever do this LMAO
327330 normalizeLayout->addWidget (normalizeLabel, 0 , 1 );
328331 normalizeLayout->addWidget (m_normalizeMode, 1 , 1 );
329332
0 commit comments