Skip to content

Commit

Permalink
Fix a number of MSVC warnings.
Browse files Browse the repository at this point in the history
- Fixed many size_t conversion warnings
- Used enum class for FilterRule::Subject and FilterRule::Operation to fix intellisense warnings.
  • Loading branch information
cameronwhite committed Jul 8, 2020
1 parent c5d39b2 commit 1ee78ab
Show file tree
Hide file tree
Showing 20 changed files with 118 additions and 103 deletions.
2 changes: 1 addition & 1 deletion source/actions/addinstrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ AddInstrument::AddInstrument(Score &score, const Instrument &instrument)
: QUndoCommand(QObject::tr("Add Instrument")),
myScore(score),
myInstrument(instrument),
myIndex(score.getInstruments().size())
myIndex(static_cast<int>(score.getInstruments().size()))
{
}

Expand Down
2 changes: 1 addition & 1 deletion source/actions/addplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ AddPlayer::AddPlayer(Score &score, const Player &player)
: QUndoCommand(QObject::tr("Add Player")),
myScore(score),
myPlayer(player),
myPlayerIndex(score.getPlayers().size())
myPlayerIndex(static_cast<int>(score.getPlayers().size()))
{
}

Expand Down
5 changes: 4 additions & 1 deletion source/actions/editviewfilters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ void EditViewFilters::undo()
void EditViewFilters::setViewFilters(const std::vector<ViewFilter> &filters)
{
while (!myScore.getViewFilters().empty())
myScore.removeViewFilter(myScore.getViewFilters().size() - 1);
{
myScore.removeViewFilter(
static_cast<int>(myScore.getViewFilters().size()) - 1);
}

for (const ViewFilter &filter : filters)
myScore.insertViewFilter(filter);
Expand Down
2 changes: 1 addition & 1 deletion source/app/scorearea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void ScoreArea::renderDocument(const Document &document)

myScoreInfoBlock = ScoreInfoRenderer::render(score.getScoreInfo(), activePalette->text().color());

myRenderedSystems.reserve(score.getSystems().size());
myRenderedSystems.reserve(static_cast<int>(score.getSystems().size()));
for (unsigned int i = 0; i < score.getSystems().size(); ++i)
myRenderedSystems.append(nullptr);

Expand Down
7 changes: 4 additions & 3 deletions source/dialogs/directiondialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ void DirectionDialog::onAddDirection()
ui->directionComboBox->addItem(
QString::number(myDirection.getSymbols().size()));

ui->directionComboBox->setCurrentIndex(myDirection.getSymbols().size() - 1);
ui->directionComboBox->setCurrentIndex(
static_cast<int>(myDirection.getSymbols().size()) - 1);

if (myDirection.getSymbols().size() == MAX_SYMBOLS)
ui->addDirectionButton->setDisabled(true);
Expand All @@ -116,8 +117,8 @@ void DirectionDialog::onRemoveDirection()
for (unsigned long i = 0; i < myDirection.getSymbols().size(); ++i)
ui->directionComboBox->addItem(QString::number(i + 1));

ui->directionComboBox->setCurrentIndex(
std::min<int>(index, myDirection.getSymbols().size() - 1));
ui->directionComboBox->setCurrentIndex(std::min<int>(
index, static_cast<int>(myDirection.getSymbols().size()) - 1));

// Update the Add/Remove buttons.
ui->addDirectionButton->setEnabled(true);
Expand Down
15 changes: 8 additions & 7 deletions source/dialogs/filterrulewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ class StringFilterValidator : public QValidator
// Verify that the filter is valid.
try
{
FilterRule rule(FilterRule::PLAYER_NAME, input.toStdString());
FilterRule rule(FilterRule::Subject::PlayerName,
input.toStdString());
return State::Acceptable;
}
catch (const std::exception &e)
catch (const std::exception &)
{
return State::Intermediate;
}
Expand Down Expand Up @@ -93,12 +94,12 @@ FilterRuleWidget::~FilterRuleWidget()

void FilterRuleWidget::update(const FilterRule &rule)
{
ui->subjectComboBox->setCurrentIndex(rule.getSubject());
ui->stackedWidget->setCurrentIndex(rule.getSubject());
ui->subjectComboBox->setCurrentIndex(int(rule.getSubject()));
ui->stackedWidget->setCurrentIndex(int(rule.getSubject()));

ui->regexLineEdit->setText(QString::fromStdString(rule.getStringValue()));

ui->operationComboBox->setCurrentIndex(rule.getOperation());
ui->operationComboBox->setCurrentIndex(int(rule.getOperation()));
ui->stringsSpinBox->setValue(rule.getIntValue());
}

Expand All @@ -108,13 +109,13 @@ void FilterRuleWidget::updateRule()
{
if (ui->regexLineEdit->hasAcceptableInput())
{
emit changed(FilterRule(FilterRule::PLAYER_NAME,
emit changed(FilterRule(FilterRule::Subject::PlayerName,
ui->regexLineEdit->text().toStdString()));
}
}
else
{
emit changed(FilterRule(FilterRule::NUM_STRINGS,
emit changed(FilterRule(FilterRule::Subject::NumStrings,
static_cast<FilterRule::Operation>(
ui->operationComboBox->currentIndex()),
ui->stringsSpinBox->value()));
Expand Down
7 changes: 4 additions & 3 deletions source/dialogs/viewfilterdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ void ViewFilterDialog::update(const std::vector<std::string> &names,
ui->nameLineEdit->setText(QString::fromStdString(names[*selection]));

// Add new widgets if necessary.
for (size_t i = ui->filterRuleLayout->count(), n = rules.size(); i < n;
++i)
for (int i = ui->filterRuleLayout->count(),
n = static_cast<int>(rules.size());
i < n; ++i)
{
auto widget = new FilterRuleWidget(this);
ui->filterRuleLayout->addWidget(widget);
Expand All @@ -118,7 +119,7 @@ void ViewFilterDialog::update(const std::vector<std::string> &names,
}

// Update widgets.
for (size_t i = 0, n = rules.size(); i < n; ++i)
for (int i = 0, n = static_cast<int>(rules.size()); i < n; ++i)
{
auto widget = dynamic_cast<FilterRuleWidget *>(
ui->filterRuleLayout->itemAt(i)->widget());
Expand Down
2 changes: 1 addition & 1 deletion source/dialogs/viewfilterpresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void ViewFilterPresenter::removeSelectedFilter()
if (myFilters.empty())
mySelection.reset();
else if (*mySelection == static_cast<int>(myFilters.size()))
*mySelection = myFilters.size() - 1;
*mySelection = static_cast<int>(myFilters.size()) - 1;

updateView();
}
Expand Down
10 changes: 5 additions & 5 deletions source/formats/gp7/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ convertPlayers(const std::vector<Gp7::Track> &tracks, Score &score,
for (const Gp7::Track &track : tracks)
{
assert(!track.mySounds.empty());
const int instrument_idx = score.getInstruments().size();
const int instrument_idx = static_cast<int>(score.getInstruments().size());

for (const Gp7::Sound &sound : track.mySounds)
{
Expand Down Expand Up @@ -103,7 +103,7 @@ convertPlayers(const std::vector<Gp7::Track> &tracks, Score &score,
tuning.setCapo(staff.myCapo);
player.setTuning(tuning);

const int player_idx = score.getPlayers().size();
const int player_idx = static_cast<int>(score.getPlayers().size());
score.insertPlayer(player);

// Each player will be assigned its own staff, and is initially
Expand Down Expand Up @@ -946,7 +946,7 @@ convertSystem(const Gp7::Document &doc, Score &score, int bar_begin,
int system_bar_idx = 0;
for (int bar_idx = bar_begin; bar_idx < bar_end; ++bar_idx)
{
const int num_staves = score.getPlayers().size();
const int num_staves = static_cast<int>(score.getPlayers().size());
const Gp7::MasterBar &master_bar = doc.myMasterBars.at(bar_idx);

// If the previous bar was a repeat end, and this master bar is a
Expand Down Expand Up @@ -1108,11 +1108,11 @@ Gp7::convert(const Gp7::Document &doc, Score &score)
// The multi-track layout is sometimes invalid (particularly for .gpx
// files). So, fall back to the first track's layout if we need to.
std::vector<int> layout = doc.myScoreInfo.myScoreSystemsLayout;
if (!isValidLayout(layout, doc.myMasterBars.size()) &&
if (!isValidLayout(layout, static_cast<int>(doc.myMasterBars.size())) &&
!doc.myTracks.empty())
{
layout = doc.myTracks[0].mySystemsLayout;
assert(isValidLayout(layout, doc.myMasterBars.size()));
assert(isValidLayout(layout, static_cast<int>(doc.myMasterBars.size())));
}

int bar_idx = 0;
Expand Down
10 changes: 5 additions & 5 deletions source/formats/gp7/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,31 +754,31 @@ parseRhythms(const pugi::xml_node &rhythms_node)
void
Gp7::Document::addBar(MasterBar &master_bar, Bar bar)
{
const int bar_id = myBars.size();
const int bar_id = static_cast<int>(myBars.size());
myBars[bar_id] = std::move(bar);
master_bar.myBarIds.push_back(bar_id);
}

void
Gp7::Document::addVoice(Bar &bar, Voice voice)
{
const int voice_id = myVoices.size();
const int voice_id = static_cast<int>(myVoices.size());
myVoices[voice_id] = std::move(voice);
bar.myVoiceIds.push_back(voice_id);
}

void
Gp7::Document::addBeat(Voice &voice, Beat beat)
{
const int beat_id = myBeats.size();
const int beat_id = static_cast<int>(myBeats.size());
myBeats[beat_id] = std::move(beat);
voice.myBeatIds.push_back(beat_id);
}

void
Gp7::Document::addNote(Beat &beat, Note note)
{
const int note_id = myNotes.size();
const int note_id = static_cast<int>(myNotes.size());
myNotes[note_id] = std::move(note);
beat.myNoteIds.push_back(note_id);
}
Expand All @@ -787,7 +787,7 @@ void
Gp7::Document::addRhythm(Beat &beat, Rhythm rhythm)
{
// TODO - consolidate identical rhythms?
const int rhythm_id = myRhythms.size();
const int rhythm_id = static_cast<int>(myRhythms.size());
myRhythms[rhythm_id] = std::move(rhythm);
beat.myRhythmId = rhythm_id;
}
Expand Down
16 changes: 9 additions & 7 deletions source/formats/guitar_pro/gp345to7converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ convertScoreInfo(const Gp::Document &doc)
// Decide how the measures are split into systems.
// For now just do three measures per system.
static constexpr int measures_per_system = 3;
const int num_systems = doc.myMeasures.size() / measures_per_system;
const int remainder = doc.myMeasures.size() % measures_per_system;
const int num_measures = static_cast<int>(doc.myMeasures.size());
const int num_systems = num_measures / measures_per_system;
const int remainder = num_measures % measures_per_system;
std::vector<int> &layout = gp7_info.myScoreSystemsLayout;

layout.insert(layout.begin(), num_systems, measures_per_system);
Expand Down Expand Up @@ -91,7 +92,7 @@ convertTracks(const Gp::Document &doc)
static int
convertStringNumber(const Gp::Track &track, int string)
{
return track.myTuning.size() - string - 1;
return static_cast<int>(track.myTuning.size()) - string - 1;
}

static std::optional<Gp7::Beat>
Expand Down Expand Up @@ -250,8 +251,8 @@ convertBeat(const Gp::Beat &beat, const Gp::Track &track,
rhythm.myTupletNum = *beat.myIrregularGrouping;
// The denominator of the irregular grouping is the nearest
// power of 2 (from below).
rhythm.myTupletDenom = std::pow(
2, std::floor(std::log(rhythm.myTupletNum) / std::log(2.0)));
rhythm.myTupletDenom = static_cast<int>(std::pow(
2, std::floor(std::log(rhythm.myTupletNum) / std::log(2.0))));
}

gp7_doc.addRhythm(gp7_beat, std::move(rhythm));
Expand Down Expand Up @@ -486,8 +487,9 @@ convertMasterBars(const Gp::Document &doc, Gp7::Document &gp7_doc)
gp7_doc.addBeat(gp7_voice, std::move(*grace_beat));

Gp7::Beat gp7_beat;
convertBeat(beat, track, gp7_doc, gp7_voice, staff_idx,
voice_idx, gp7_beat);
convertBeat(beat, track, gp7_doc, gp7_voice,
static_cast<int>(staff_idx),
static_cast<int>(voice_idx), gp7_beat);
gp7_doc.addBeat(gp7_voice, std::move(gp7_beat));

// Add tempo changes to the measure.
Expand Down
4 changes: 2 additions & 2 deletions source/midi/midifile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ findNextTempoMarker(const Score &score, SystemLocation location,
MidiEventList event_list;
const int current_tick = -1;

const int num_systems = score.getSystems().size();
const int num_systems = static_cast<int>(score.getSystems().size());
while (location.getSystem() < num_systems)
{
const System &system = score.getSystems()[location.getSystem()];
Expand Down Expand Up @@ -416,7 +416,7 @@ MidiFile::addTempoEvent(MidiEventList &event_list, int current_tick,

// We're working in microseconds, so a tempo change event every
// millisecond seems reasonable ...
const int num_events = std::abs(delta_tempo.count()) / 1000;
const int num_events = static_cast<int>(std::abs(delta_tempo.count()) / 1000);
if (!num_events)
return current_tempo;

Expand Down
10 changes: 6 additions & 4 deletions source/score/score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,15 @@ void ScoreUtils::addStandardFilters(Score &score)

ViewFilter filter_guitars;
filter_guitars.setDescription("Guitars");
filter_guitars.addRule(
FilterRule(FilterRule::NUM_STRINGS, FilterRule::GREATER_THAN_EQUAL, 6));
filter_guitars.addRule(FilterRule(FilterRule::Subject::NumStrings,
FilterRule::Operation::GreaterThanEqual,
6));
score.insertViewFilter(filter_guitars);

ViewFilter filter_basses;
filter_basses.setDescription("Basses");
filter_basses.addRule(
FilterRule(FilterRule::NUM_STRINGS, FilterRule::LESS_THAN_EQUAL, 5));
filter_basses.addRule(FilterRule(FilterRule::Subject::NumStrings,
FilterRule::Operation::LessThanEqual,
5));
score.insertViewFilter(filter_basses);
}
6 changes: 3 additions & 3 deletions source/score/utils/scoremerger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,9 @@ static bool areStavesIncompatible(
{
return areStavesIncompatible(dest_loc, guitar_caret, guitar_bar,
end_guitar_bar, 0, num_guitar_staves) ||
areStavesIncompatible(dest_loc, bass_caret, bass_bar, end_bass_bar,
num_guitar_staves,
dest_loc.getSystem().getStaves().size());
areStavesIncompatible(
dest_loc, bass_caret, bass_bar, end_bass_bar, num_guitar_staves,
static_cast<int>(dest_loc.getSystem().getStaves().size()));
}

static void insertNewSystem(Score &score)
Expand Down
55 changes: 28 additions & 27 deletions source/score/viewfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ struct FilterRule::RegexImpl
};

FilterRule::FilterRule()
: mySubject(Subject::PLAYER_NAME),
myOperation(Operation::EQUAL),
: mySubject(Subject::PlayerName),
myOperation(Operation::Equal),
myIntValue(0)
{
}

FilterRule::FilterRule(Subject subject, std::string value)
: mySubject(subject),
myOperation(Operation::EQUAL),
myOperation(Operation::Equal),
myIntValue(0),
myStrValue(std::move(value)),
myRegexImpl(std::make_unique<RegexImpl>(myStrValue))
Expand Down Expand Up @@ -82,32 +82,33 @@ bool FilterRule::accept(const Player &player) const
{
switch (mySubject)
{
case PLAYER_NAME:
return std::regex_match(player.getDescription(), myRegexImpl->myRegex);
case NUM_STRINGS:
{
const int value = player.getTuning().getStringCount();

switch (myOperation)
case Subject::PlayerName:
return std::regex_match(player.getDescription(),
myRegexImpl->myRegex);
case Subject::NumStrings:
{
case LESS_THAN:
return value < myIntValue;
case LESS_THAN_EQUAL:
return value <= myIntValue;
case EQUAL:
return value == myIntValue;
case GREATER_THAN:
return value > myIntValue;
case GREATER_THAN_EQUAL:
return value >= myIntValue;
}
const int value = player.getTuning().getStringCount();

assert(false);
return false;
}
default:
assert(!"Unexpected subject for filter.");
return false;
switch (myOperation)
{
case Operation::LessThan:
return value < myIntValue;
case Operation::LessThanEqual:
return value <= myIntValue;
case Operation::Equal:
return value == myIntValue;
case Operation::GreaterThan:
return value > myIntValue;
case Operation::GreaterThanEqual:
return value >= myIntValue;
}

assert(false);
return false;
}
default:
assert(!"Unexpected subject for filter.");
return false;
}
}

Expand Down
Loading

0 comments on commit 1ee78ab

Please sign in to comment.