Skip to content
Permalink
Browse files

This commit contains changes required for MuseScore to compile under …

…MSVC with no warnings.

This commit contains changes required for MuseScore to compile under MSVC with no warnings.

MuseScore is being compiled with the /W4 setting (warning level 4), which is similar to -wall -wextra on clang. This generates lots of warnings on MSVC, mainly for non-standard constructs and for constructs which might be bugs or might lead to bugs.

Most warnings are in the following categories:
- Name hiding: a variable hides a variable with the same name on a larger scope (or a field, or a function parameter). This can easily lead to bugs, and it is a best practice to avoid hiding variable names (see recommendation ES.12 in the C++ Core Guidelines by Stroustrop & Sutter (http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-reuse : ES.12: Do not reuse names in nested scopes)
- Narrowing conversion: a numeric conversion results in loss of significant digits (for example, double -> float). The general recommendation is to use a cast to indicate this is designed behaviour.
- Unreachable code: in several instances, there is unreachable code. The unreachable code is commented out.
- (Potentially) uninitialized local variable. Just initialized the vars.
- foreach(,) -> for(:): this does not generate a warning per-se (only a few of these generate warnings due to name hiding), but changed in keeping with "MuseScore Coding Rules" (https://musescore.org/en/handbook/musescore-coding-rules#Loops), which tells explicitly "Use C++11's "for" instead of Qt's "foreach":" ... "If you happen to be fixing some code and see a "foreach", please change that loop into a "for"."

Most changes are in the categories indicated above. The next listing shows detailed changes for files which are *not* of the aforementioned types.

- all.h: Disable warning C4127 (conditional expression is constant - generated in Qt header file qvector.h)
- awl/aslider.h: unreachable code.
- awl/knob.cpp: name hiding
- awl/mslider.cpp: name hiding
- awl/slider.cpp: name hiding
- bww2mxml/parser.cpp: name hiding
- effects/compressor/compressor.cpp: narrowing conversion
- effects/zita1/zitagui.cpp: name hiding
- fluid/fluid.cpp: foreach replacement. Name hiding.
- fluid/mod.cpp: name hiding.
- fluid/sfont.cpp: foreach replacement. Name hiding. Initialize vars.
- fluid/voice.cpp: Name hiding.
- libmscore/accidental.cpp: Name hiding.
- libmscore/ambitus.cpp: Initialize vars.
- libmscore/barline.cpp: Name hiding. Unreachable code.
- libmscore/beam.cpp: Name hiding.
- libmscore/chordrest.cpp: Unreachable code.
- libmscore/scorefile.cpp: Name hiding.
- manual/genManual.cpp: Name hiding. foreach replacement.
- midi/midifile.cpp: Name hiding. Unreachable code.
- omr/importpdf.cpp: Name hiding. foreach replacement.
- omr/omr.cpp: Name hiding. foreach replacement.
- omr/omrpage.cpp: Name hiding. foreach replacement.
- omr/omrview.cpp: Name hiding. foreach replacement.
- synthesizer/event.cpp: Unreachable code.
- zerberus\channel.cpp: Narrowing conversion.
- zerberus\instrument.cpp: Name hiding.
- zerberus\sfz.cpp: Name hiding.
- zerberus\voice.h: Suppress warning C4201: "nonstandard extension used: nameless struct/union"
- zerberus\zerberus.cpp: Name hiding. Unreferenced parameter.
- zerberus\zerberusgui.cpp: Name hiding.
  • Loading branch information...
afdeprado authored and handrok committed May 3, 2018
1 parent 3acc363 commit 33dff96a20ea6d55974baa4ec977da9a196c925a
6 all.h
@@ -53,6 +53,12 @@
#include <functional>
#include <memory>

// Disable warning C4127: conditional expression is constant in VS2017 (generated in header file qvector.h)
#if (defined (_MSCVER) || defined (_MSC_VER))
#pragma warning ( push )
#pragma warning ( disable: 4127)
#endif

#include <QtGui>
#include <QLoggingCategory>
#include <QModelIndex>
@@ -302,7 +302,8 @@ QString AccessibleAbstractSlider::text(QAccessible::Text t) const
default:
return QString();
}
return QString();
// Eliminate "unreachable code"
// return QString();
}

void AccessibleAbstractSlider::valueChanged(double, int)
@@ -261,11 +261,11 @@ void Knob::paintEvent(QPaintEvent* /*ev*/)
if (_center) {
if (points)
delete points;
qreal x = ar.width() / 2 + ar.x();
qreal y = ar.y() - _markSize - _scaleWidth/2;
points = new QPainterPath(QPointF(x - markSize2, y));
points->lineTo(x + markSize2, y);
points->lineTo(x, _markSize + y);
qreal x3 = ar.width() / 2 + ar.x();
qreal y3 = ar.y() - _markSize - _scaleWidth/2;
points = new QPainterPath(QPointF(x3 - markSize2, y3));
points->lineTo(x3 + markSize2, y3);
points->lineTo(x3, _markSize + y3);
points->closeSubpath();
p.drawPath(*points);
}
@@ -188,24 +188,24 @@ void MeterSlider::paintEvent(QPaintEvent* ev)
p.setPen(QPen(Qt::white, 2));

for (int i = 0; i < _channel; ++i) {
int h = mh - (lrint(fast_log10(meterval[i]) * -20.0f * mh / range));
if (h < 0)
h = 0;
else if (h > mh)
h = mh;
int h1 = mh - (lrint(fast_log10(meterval[i]) * -20.0f * mh / range));
if (h1 < 0)
h1 = 0;
else if (h1 > mh)
h1 = mh;

p.drawPixmap(x, y1 + mh - h, mw, h, onPm, 0, mh - h, mw, h);
p.drawPixmap(x, y1, mw, mh - h, offPm, 0, 0, mw, mh - h);
p.drawPixmap(x, y1 + mh - h1, mw, h1, onPm, 0, mh - h1, mw, h1);
p.drawPixmap(x, y1, mw, mh - h1, offPm, 0, 0, mw, mh - h1);

//---------------------------------------------------
// draw peak line
//---------------------------------------------------

h = mh - (lrint(fast_log10(meterPeak[i]) * -20.0f * mh / range));
if (h > mh)
h = mh;
if (h > 0)
p.drawLine(x, y3 - h, x + mw, y3 - h);
h1 = mh - (lrint(fast_log10(meterPeak[i]) * -20.0f * mh / range));
if (h1 > mh)
h1 = mh;
if (h1 > 0)
p.drawLine(x, y3 - h1, x + mw, y3 - h1);

x += mw;
}
@@ -101,8 +101,8 @@ void Slider::updateKnob()
int kw = _sliderSize.width();
points->moveTo(0.0, 0.0);
if (orient == Qt::Vertical) {
int kh = _sliderSize.height();
int kh2 = kh / 2;
int kh1 = _sliderSize.height();
int kh2 = kh1 / 2;
points->lineTo(kw, -kh2);
points->lineTo(kw, kh2);
}
@@ -711,13 +711,13 @@ namespace Bww {
{
qDebug() << "Parser::parseGraces() value:" << qPrintable(lex.symValue());

const QString type = "32";
const QString c_type = "32";
const int dots = 0;
QStringList graces = lex.symValue().split(" ");
for (int i = 0; i < graces.size(); ++i)
{
const QString beam = graceBeam(graces.size(), i);
NoteDescription noteDesc(graces.at(i), beam, type, dots, false, false, ST_NONE, true);
NoteDescription noteDesc(graces.at(i), beam, c_type, dots, false, false, ST_NONE, true);
if (measures.isEmpty())
{
errorHandler("cannot append note: no measure");
@@ -76,8 +76,8 @@ static inline float f_max(float x, float a)

static inline void round_to_zero(volatile float *f)
{
*f += 1e-18;
*f -= 1e-18;
*f += 1e-18f;
*f -= 1e-18f;
}

// Linearly interpolate [ = a * (1 - f) + b * f]
@@ -67,8 +67,8 @@ ZitaEffectGui::ZitaEffectGui(ZitaReverb* effect, QWidget* parent)

void ZitaEffectGui::updateValues()
{
for (Rotary& r : rotary) {
r.value = effect()->value(r.id);
for (Rotary& rot : rotary) {
rot.value = effect()->value(rot.id);
}
update();
}
@@ -135,10 +135,10 @@ void ZitaEffectGui::paintEvent(QPaintEvent*)
x += pix.width();
}
p.setBrush(QColor(0x3f, 0x3f, 0x3f));
for (const Rotary& r : rotary) {
for (const Rotary& rot : rotary) {
p.save();
p.translate(r.x + 11.5, r.y + 11.5);
p.rotate(r.value * 270.0 - 225);
p.translate(rot.x + 11.5, rot.y + 11.5);
p.rotate(rot.value * 270.0 - 225);
p.drawRect(QRectF(-2, -2, 11.5 + 2, 4));
p.restore();
}
@@ -149,7 +149,7 @@ void Fluid::play(const PlayEvent& event)
//
// process note off
//
foreach (Voice* v, activeVoices) {
for (Voice* v : activeVoices) {
if (v->ON() && (v->chan == ch) && (v->key == key))
v->noteoff();
}
@@ -169,7 +169,7 @@ void Fluid::play(const PlayEvent& event)
* several voice processes, for example a stereo sample. Don't
* release those...
*/
foreach(Voice* v, activeVoices) {
for(Voice* v : activeVoices) {
if (v->isPlaying() && (v->chan == ch) && (v->key == key) && (v->get_id() != noteid))
v->noteoff();
}
@@ -205,7 +205,7 @@ void Fluid::play(const PlayEvent& event)

void Fluid::damp_voices(int chan)
{
foreach(Voice* v, activeVoices) {
for(Voice* v : activeVoices) {
if ((v->chan == chan) && v->SUSTAINED())
v->noteoff();
}
@@ -217,7 +217,7 @@ void Fluid::damp_voices(int chan)

void Fluid::allNotesOff(int chan)
{
foreach(Voice* v, activeVoices) {
for(Voice* v : activeVoices) {
if (chan == -1 || v->chan == chan)
v->noteoff();
}
@@ -231,7 +231,7 @@ void Fluid::allNotesOff(int chan)

void Fluid::allSoundsOff(int chan)
{
foreach(Voice* v, activeVoices) {
for(Voice* v : activeVoices) {
if (chan == -1 || v->chan == chan)
v->off();
}
@@ -246,9 +246,9 @@ void Fluid::allSoundsOff(int chan)

void Fluid::system_reset()
{
foreach(Voice* v, activeVoices)
for(Voice* v : activeVoices)
v->off();
foreach(Channel* c, channel)
for(Channel* c : channel)
c->reset();
}

@@ -260,7 +260,7 @@ void Fluid::system_reset()
*/
void Fluid::modulate_voices(int chan, bool is_cc, int ctrl)
{
foreach(Voice* v, activeVoices) {
for(Voice* v : activeVoices) {
if (v->chan == chan)
v->modulate(is_cc, ctrl);
}
@@ -275,7 +275,7 @@ void Fluid::modulate_voices(int chan, bool is_cc, int ctrl)
*/
void Fluid::modulate_voices_all(int chan)
{
foreach(Voice* v, activeVoices) {
for(Voice* v : activeVoices) {
if (v->chan == chan)
v->modulate_all();
}
@@ -345,18 +345,18 @@ void Fluid::program_change(int chan, int prognum)
preset = find_preset(0, 0);
}

unsigned sfont_id = preset? preset->sfont->id() : 0;
c->setSfontnum(sfont_id);
unsigned sfont_idl = preset? preset->sfont->id() : 0;
c->setSfontnum(sfont_idl);
c->setPreset(preset);
}

/*
* fluid_synth_get_program
*/
void Fluid::get_program(int chan, unsigned* sfont_id, unsigned* bank_num, unsigned* preset_num)
void Fluid::get_program(int chan, unsigned* sfont_idl, unsigned* bank_num, unsigned* preset_num)
{
Channel* c = channel[chan];
*sfont_id = c->getSfontnum();
*sfont_idl = c->getSfontnum();
*bank_num = c->getBanknum();
*preset_num = c->getPrognum();
}
@@ -365,17 +365,17 @@ void Fluid::get_program(int chan, unsigned* sfont_id, unsigned* bank_num, unsign
// program_select
//---------------------------------------------------------

bool Fluid::program_select(int chan, unsigned sfont_id, unsigned bank_num, unsigned preset_num)
bool Fluid::program_select(int chan, unsigned sfont_idl, unsigned bank_num, unsigned preset_num)
{
Channel* c = channel[chan];
Preset* preset = get_preset(sfont_id, bank_num, preset_num);
Preset* preset = get_preset(sfont_idl, bank_num, preset_num);
if (preset == 0) {
qDebug("There is no preset with bank number %d and preset number %d in SoundFont %d", bank_num, preset_num, sfont_id);
qDebug("There is no preset with bank number %d and preset number %d in SoundFont %d", bank_num, preset_num, sfont_idl);
return false;
}

/* inform the channel of the new bank and program number */
c->setSfontnum(sfont_id);
c->setSfontnum(sfont_idl);
c->setBanknum(bank_num);
c->setPrognum(preset_num);
c->setPreset(preset);
@@ -399,7 +399,7 @@ void Fluid::update_presets()
void Fluid::process(unsigned len, float* out, float* effect1, float* effect2)
{
if (mutex.tryLock()) {
foreach (Voice* v, activeVoices)
for (Voice* v : activeVoices)
v->write(len, out, effect1, effect2);
mutex.unlock();
}
@@ -418,7 +418,7 @@ void Fluid::free_voice_by_kill()
float this_voice_prio;
Voice* best_voice = 0;

foreach(Voice* v, activeVoices) {
for(Voice* v : activeVoices) {
/* Determine, how 'important' a voice is.
* Start with an arbitrary number */
this_voice_prio = 10000.;
@@ -534,7 +534,7 @@ void Fluid::start_voice(Voice* voice)

/* Kill all notes on the same channel with the same exclusive class */

foreach(Voice* existing_voice, activeVoices) {
for(Voice* existing_voice : activeVoices) {
/* Existing voice does not play? Leave it alone. */
if (!existing_voice->isPlaying())
continue;
@@ -597,7 +597,7 @@ void Fluid::updatePatchList()
QStringList Fluid::soundFonts() const
{
QStringList sf;
foreach (SFont* f, sfonts)
for (SFont* f : sfonts)
sf.append(QFileInfo(f->get_name()).fileName());
return sf;
}
@@ -615,11 +615,11 @@ bool Fluid::loadSoundFonts(const QStringList& sl)
return true;
}
QMutexLocker locker(&mutex);
foreach(Voice* v, activeVoices)
for(Voice* v : activeVoices)
v->off();
foreach(Channel* c, channel)
for(Channel* c : channel)
c->reset();
foreach (SFont* sf, sfonts)
for (SFont* sf : sfonts)
sfunload(sf->id());
locker.unlock();
bool ok = true;
@@ -632,7 +632,7 @@ bool Fluid::loadSoundFonts(const QStringList& sl)
QString path;
QFileInfo fis(s);
QString fileName = fis.fileName();
foreach (const QFileInfo& fi, l) {
for (const QFileInfo& fi : l) {
if (fi.fileName() == fileName) {
path = fi.absoluteFilePath();
break;
@@ -674,7 +674,7 @@ bool Fluid::addSoundFont(const QString& s)
bool Fluid::removeSoundFont(const QString& s)
{
QMutexLocker locker(&mutex);
foreach(Voice* v, activeVoices)
for(Voice* v : activeVoices)
v->off();
SFont* sf = get_sfont_by_name(s);
sfunload(sf->id());
@@ -741,7 +741,7 @@ bool Fluid::sfunload(int id)

SFont* Fluid::get_sfont_by_id(int id)
{
foreach(SFont* sf, sfonts) {
for(SFont* sf : sfonts) {
if (sf->id() == id)
return sf;
}
@@ -754,7 +754,7 @@ SFont* Fluid::get_sfont_by_id(int id)

SFont* Fluid::get_sfont_by_name(const QString& name)
{
foreach(SFont* sf, sfonts) {
for(SFont* sf : sfonts) {
if (QFileInfo(sf->get_name()).fileName() == name)
return sf;
}
@@ -769,7 +769,7 @@ SFont* Fluid::get_sfont_by_name(const QString& name)

void Fluid::set_interp_method(int chan, int interp_method)
{
foreach(Channel* c, channel) {
for(Channel* c : channel) {
if (chan < 0 || c->getNum() == chan)
c->setInterpMethod(interp_method);
}
@@ -782,7 +782,7 @@ void Fluid::set_interp_method(int chan, int interp_method)
void Fluid::set_gen(int chan, int param, float value)
{
channel[chan]->setGen(param, value, 0);
foreach(Voice* v, activeVoices) {
for(Voice* v : activeVoices) {
if (v->chan == chan)
v->set_param(param, value, 0);
}
@@ -816,7 +816,7 @@ void Fluid::set_gen2(int chan, int param, float value, int absolute, int normali
float v = (normalized)? fluid_gen_scale(param, value) : value;
channel[chan]->setGen(param, v, absolute);

foreach(Voice* vo, activeVoices) {
for(Voice* vo : activeVoices) {
if (vo->chan == chan)
vo->set_param(param, v, absolute);
}
@@ -841,7 +841,7 @@ SynthesizerGroup Fluid::state() const
g.setName(name());

QStringList sfl = soundFonts();
foreach (QString sf, sfl)
for (QString sf : sfl)
g.push_back(IdValue(0, sf));

return g;
@@ -870,7 +870,7 @@ bool Fluid::setState(const SynthesizerGroup& sp)
static void collectFiles(QFileInfoList* l, const QString& path)
{
QDir dir(path);
foreach (const QFileInfo& s, dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot)) {
for (const QFileInfo& s : dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot)) {
if (path == s.absoluteFilePath())
return;

0 comments on commit 33dff96

Please sign in to comment.
You can’t perform that action at this time.