Skip to content

Commit

Permalink
Merge pull request #1249 from trig-ger/midi_fixes
Browse files Browse the repository at this point in the history
Fixes for MIDI import
  • Loading branch information
lasconic committed Sep 1, 2014
2 parents ce144a3 + 6f0ef16 commit 1b54253
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 27 deletions.
27 changes: 13 additions & 14 deletions mscore/importmidi.cpp
Expand Up @@ -164,7 +164,7 @@ void quantizeAllTracks(std::multimap<int, MTrack> &tracks,
}
}
const auto basicQuant = Quantize::quantValueToFraction(
opers.data()->trackOpers.quantValue.defaultValue());
opers.data()->trackOpers.quantValue.value(mtrack.indexOfOperation));

MChord::setBarIndexes(mtrack.chords, basicQuant, lastTick, sigmap);
MidiTuplet::findAllTuplets(mtrack.tuplets, mtrack.chords, sigmap, lastTick, basicQuant);
Expand Down Expand Up @@ -716,14 +716,10 @@ void createInstruments(Score *score, QList<MTrack> &tracks)
for (int idx = 0; idx < ntracks; ++idx) {
MTrack& track = tracks[idx];
Part* part = new Part(score);
Staff* s = new Staff(score);
s->setPart(part);
part->insertStaff(s, 0);
score->staves().push_back(s);
track.staff = s;

if (track.mtrack->drumTrack()) {
s->setStaffType(StaffType::preset(StaffTypes::PERC_DEFAULT));
part->setStaves(1);
part->staff(0)->setStaffType(StaffType::preset(StaffTypes::PERC_DEFAULT));
part->instr()->setDrumset(smDrumset);
part->instr()->setUseDrumset(DrumsetKind::DEFAULT_DRUMS);
}
Expand All @@ -732,17 +728,20 @@ void createInstruments(Score *score, QList<MTrack> &tracks)
&& isGrandStaff(tracks[idx], tracks[idx + 1])) {
// assume that the current track and the next track
// form a piano part
s->setBracket(0, BracketType::BRACE);
s->setBracketSpan(0, 2);
part->setStaves(2);
part->staff(0)->setBracket(0, BracketType::BRACE);
part->staff(0)->setBracketSpan(0, 2);

Staff* ss = new Staff(score);
ss->setPart(part);
part->insertStaff(ss, 1);
score->staves().push_back(ss);
++idx;
tracks[idx].staff = ss;
tracks[idx].staff = part->staff(1);
}
else {
part->setStaves(1);
}
}

track.staff = part->staff(0);
part->staves()->front()->setBarLineSpan(part->nstaves());
score->appendPart(part);
}
}
Expand Down
42 changes: 30 additions & 12 deletions mscore/importmidi_model.cpp
Expand Up @@ -810,13 +810,19 @@ Qt::ItemFlags TracksModel::itemFlags(int row, int col) const
const int trackIndex = trackIndexFromRow(row);

if (_columns[col]->isVisible(trackIndex)) {
if (_columns[col]->value(0).type() == QVariant::Bool)
if (_columns[col]->value(0).type() == QVariant::Bool) {
flags |= Qt::ItemIsUserCheckable;
else if (_columns[col]->isEditable()
&& editableSingleTrack(trackIndex, col)) {
QVariant value = _columns[col]->value(0);
if (value.type() != QVariant::Bool) // not checkboxes
}
else {
if (trackIndex == -1) {
flags |= Qt::ItemIsEditable;
}
else if (_columns[col]->isEditable()
&& editableSingleTrack(trackIndex, col)) {
QVariant value = _columns[col]->value(0);
if (value.type() != QVariant::Bool) // not checkboxes
flags |= Qt::ItemIsEditable;
}
}
}
return flags;
Expand All @@ -831,13 +837,18 @@ Qt::ItemFlags TracksModel::flags(const QModelIndex &index) const
const int trackIndex = trackIndexFromRow(index.row());

if (trackIndex == -1) { // all tracks row
for (int i = 0; i < _trackCount; ++i) {
const auto newFlags = itemFlags(rowFromTrackIndex(i), index.column());
if (newFlags) {
flags |= newFlags;
break;
if (!_columns[index.column()]->isForAllTracksOnly()) {
for (int i = 0; i < _trackCount; ++i) {
const auto newFlags = itemFlags(rowFromTrackIndex(i), index.column());
if (newFlags) {
flags |= newFlags;
break;
}
}
}
else {
flags |= itemFlags(index.row(), index.column());
}
}
else {
flags |= itemFlags(index.row(), index.column());
Expand Down Expand Up @@ -897,8 +908,10 @@ bool TracksModel::setData(const QModelIndex &index, const QVariant &value, int /

QVariant TracksModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (section < 0 || section >= (int)_columns.size())
if ((orientation == Qt::Vertical && !isRowValid(section))
|| (orientation == Qt::Horizontal && !isColumnValid(section))) {
return QVariant();
}

if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
if (!_columns.empty()) {
Expand All @@ -922,9 +935,14 @@ bool TracksModel::isTrackIndexValid(int trackIndex) const
return trackIndex >= -1 && trackIndex < _trackCount;
}

bool TracksModel::isRowValid(int row) const
{
return row >= 0 && ((_trackCount == 1) ? row < _trackCount : row <= _trackCount);
}

bool TracksModel::isColumnValid(int column) const
{
return (column >= 0 && column < (int)_columns.size());
return column >= 0 && column < (int)_columns.size();
}

} // namespace Ms
1 change: 1 addition & 0 deletions mscore/importmidi_model.h
Expand Up @@ -41,6 +41,7 @@ class TracksModel : public QAbstractTableModel

private:
bool isTrackIndexValid(int trackIndex) const;
bool isRowValid(int row) const;
bool isColumnValid(int column) const;
void forceRowDataChanged(int row);
void forceColumnDataChanged(int col);
Expand Down
2 changes: 1 addition & 1 deletion mscore/importmidi_tuplet_filter.cpp
Expand Up @@ -664,7 +664,7 @@ std::vector<int> findBestTuplets(

void removeExtraTuplets(std::vector<TupletInfo> &tuplets)
{
const size_t MAX_TUPLETS = 23; // found empirically
const size_t MAX_TUPLETS = 17; // found empirically

if (tuplets.size() <= MAX_TUPLETS)
return;
Expand Down
1 change: 1 addition & 0 deletions mtest/importmidi/m1.mscx
Expand Up @@ -45,6 +45,7 @@
<StaffType group="pitched">
</StaffType>
<bracket type="1" span="2"/>
<barLineSpan>2</barLineSpan>
</Staff>
<Staff id="2">
<StaffType group="pitched">
Expand Down
1 change: 1 addition & 0 deletions mtest/importmidi/m2.mscx
Expand Up @@ -45,6 +45,7 @@
<StaffType group="pitched">
</StaffType>
<bracket type="1" span="2"/>
<barLineSpan>2</barLineSpan>
</Staff>
<Staff id="2">
<StaffType group="pitched">
Expand Down
1 change: 1 addition & 0 deletions mtest/importmidi/m3.mscx
Expand Up @@ -45,6 +45,7 @@
<StaffType group="pitched">
</StaffType>
<bracket type="1" span="2"/>
<barLineSpan>2</barLineSpan>
</Staff>
<Staff id="2">
<StaffType group="pitched">
Expand Down
1 change: 1 addition & 0 deletions mtest/importmidi/m4.mscx
Expand Up @@ -45,6 +45,7 @@
<StaffType group="pitched">
</StaffType>
<bracket type="1" span="2"/>
<barLineSpan>2</barLineSpan>
</Staff>
<Staff id="2">
<StaffType group="pitched">
Expand Down
1 change: 1 addition & 0 deletions mtest/importmidi/m5.mscx
Expand Up @@ -45,6 +45,7 @@
<StaffType group="pitched">
</StaffType>
<bracket type="1" span="2"/>
<barLineSpan>2</barLineSpan>
</Staff>
<Staff id="2">
<StaffType group="pitched">
Expand Down
1 change: 1 addition & 0 deletions mtest/importmidi/split_2_melodies.mscx
Expand Up @@ -45,6 +45,7 @@
<StaffType group="pitched">
</StaffType>
<bracket type="1" span="2"/>
<barLineSpan>2</barLineSpan>
</Staff>
<Staff id="2">
<StaffType group="pitched">
Expand Down
1 change: 1 addition & 0 deletions mtest/importmidi/split_acid.mscx
Expand Up @@ -45,6 +45,7 @@
<StaffType group="pitched">
</StaffType>
<bracket type="1" span="2"/>
<barLineSpan>2</barLineSpan>
</Staff>
<Staff id="2">
<StaffType group="pitched">
Expand Down
1 change: 1 addition & 0 deletions mtest/importmidi/split_nontuplet.mscx
Expand Up @@ -45,6 +45,7 @@
<StaffType group="pitched">
</StaffType>
<bracket type="1" span="2"/>
<barLineSpan>2</barLineSpan>
</Staff>
<Staff id="2">
<StaffType group="pitched">
Expand Down
1 change: 1 addition & 0 deletions mtest/importmidi/split_octave.mscx
Expand Up @@ -45,6 +45,7 @@
<StaffType group="pitched">
</StaffType>
<bracket type="1" span="2"/>
<barLineSpan>2</barLineSpan>
</Staff>
<Staff id="2">
<StaffType group="pitched">
Expand Down
1 change: 1 addition & 0 deletions mtest/importmidi/split_tuplet.mscx
Expand Up @@ -45,6 +45,7 @@
<StaffType group="pitched">
</StaffType>
<bracket type="1" span="2"/>
<barLineSpan>2</barLineSpan>
</Staff>
<Staff id="2">
<StaffType group="pitched">
Expand Down
1 change: 1 addition & 0 deletions mtest/importmidi/tuplet_5_5_tuplets_rests.mscx
Expand Up @@ -45,6 +45,7 @@
<StaffType group="pitched">
</StaffType>
<bracket type="1" span="2"/>
<barLineSpan>2</barLineSpan>
</Staff>
<Staff id="2">
<StaffType group="pitched">
Expand Down
1 change: 1 addition & 0 deletions mtest/importmidi/tuplet_triplets_mixed.mscx
Expand Up @@ -45,6 +45,7 @@
<StaffType group="pitched">
</StaffType>
<bracket type="1" span="2"/>
<barLineSpan>2</barLineSpan>
</Staff>
<Staff id="2">
<StaffType group="pitched">
Expand Down

0 comments on commit 1b54253

Please sign in to comment.