Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gp-import: fixed voices numbers inside each instrument #26202

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/importexport/guitarpro/internal/gtp/gp67dombuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,17 @@ std::pair<int, std::unique_ptr<GPBar> > GP67DomBuilder::createGPBar(XmlDomNode*
} else if (nodeName == u"Voices") {
String voicesElement = innerNode.toElement().text();
StringList voices = voicesElement.split(u' ');
int currentPosition = -1;
alexpavlov96 marked this conversation as resolved.
Show resolved Hide resolved
for (const String& voiceIdx : voices) {
currentPosition++;
int idx = voiceIdx.toInt();
if (idx == -1) {
continue;
}

std::unique_ptr<GPVoice> voice;
voice = std::move(_voices.at(idx));
voice->setPosition(currentPosition);
_voices.erase(idx);
bar->addGPVoice(std::move(voice));
}
Expand Down
15 changes: 12 additions & 3 deletions src/importexport/guitarpro/internal/gtp/gpconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,18 @@ void GPConverter::convertVoices(const std::vector<std::unique_ptr<GPVoice> >& vo
fillUncompletedMeasure(ctx);
}

int currentTrackFirstVoice = ctx.curTrack;
for (const auto& voice : voices) {
ctx.curTrack = currentTrackFirstVoice + voice->position();
convertVoice(voice.get(), ctx);
ctx.curTrack++;
}

bool hasFirstVoice = std::any_of(voices.begin(), voices.end(), [](const std::unique_ptr<GPVoice>& voice) {
return voice->position() == 0;
});

if (!hasFirstVoice && _score->lastMeasure()) {
_score->setRest(_score->lastMeasure()->tick(), currentTrackFirstVoice, _score->lastMeasure()->ticks(), true, nullptr);
}
}

Expand Down Expand Up @@ -1240,13 +1249,13 @@ void GPConverter::hideRestsInEmptyMeasures(track_idx_t startTrack, track_idx_t e

// hiding rests in secondary voices for measures without any chords
if (!m_chordExistsInBar) {
rest->setGap(!mainVoice);
rest->setVisible(mainVoice);
continue;
}

// hiding rests in voices without chords
if (!m_chordExistsForVoice[voice]) {
rest->setGap(true);
rest->setVisible(false);
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/importexport/guitarpro/internal/gtp/gpvoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ class GPVoice
void addGPBeat(const std::shared_ptr<GPBeat>& b) { _beats.push_back(b); }

void setId(int id) { _id = id; }
void setPosition(int pos) { _pos = pos; }
int position() const { return _pos; }

const std::vector<std::shared_ptr<GPBeat> >& beats() const { return _beats; }

private:

int _id{ -1 };
int _id = -1; // imported id
int _pos = 0; // for defining correct track number
std::vector<std::shared_ptr<GPBeat> > _beats;
};
} // namespace mu::iex::guitarpro
Expand Down
25 changes: 16 additions & 9 deletions src/importexport/guitarpro/tests/data/basic-bend.gp-ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,22 @@
</Rest>
</voice>
<voice>
<location>
<fractions>1/4</fractions>
</location>
<location>
<fractions>1/4</fractions>
</location>
<location>
<fractions>1/4</fractions>
</location>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
</voice>
</Measure>
</Staff>
Expand Down
25 changes: 16 additions & 9 deletions src/importexport/guitarpro/tests/data/basic-bend.gpx-ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,22 @@
</Rest>
</voice>
<voice>
<location>
<fractions>1/4</fractions>
</location>
<location>
<fractions>1/4</fractions>
</location>
<location>
<fractions>1/4</fractions>
</location>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
</voice>
</Measure>
</Staff>
Expand Down
25 changes: 16 additions & 9 deletions src/importexport/guitarpro/tests/data/dotted-tuplets.gp-ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,22 @@
</Chord>
</voice>
<voice>
<location>
<fractions>1/4</fractions>
</location>
<location>
<fractions>1/4</fractions>
</location>
<location>
<fractions>1/4</fractions>
</location>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
</voice>
</Measure>
</Staff>
Expand Down
25 changes: 16 additions & 9 deletions src/importexport/guitarpro/tests/data/dotted-tuplets.gpx-ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,22 @@
</Chord>
</voice>
<voice>
<location>
<fractions>1/4</fractions>
</location>
<location>
<fractions>1/4</fractions>
</location>
<location>
<fractions>1/4</fractions>
</location>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
</voice>
</Measure>
</Staff>
Expand Down
50 changes: 32 additions & 18 deletions src/importexport/guitarpro/tests/data/dynamic.gp-ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,22 @@
</BarLine>
</voice>
<voice>
<location>
<fractions>1/4</fractions>
</location>
<location>
<fractions>1/4</fractions>
</location>
<location>
<fractions>1/4</fractions>
</location>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
</voice>
</Measure>
<Measure>
Expand Down Expand Up @@ -218,15 +225,22 @@
</Chord>
</voice>
<voice>
<location>
<fractions>1/4</fractions>
</location>
<location>
<fractions>1/4</fractions>
</location>
<location>
<fractions>1/4</fractions>
</location>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
</voice>
</Measure>
</Staff>
Expand Down
50 changes: 32 additions & 18 deletions src/importexport/guitarpro/tests/data/dynamic.gpx-ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,22 @@
</BarLine>
</voice>
<voice>
<location>
<fractions>1/4</fractions>
</location>
<location>
<fractions>1/4</fractions>
</location>
<location>
<fractions>1/4</fractions>
</location>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
</voice>
</Measure>
<Measure>
Expand Down Expand Up @@ -218,15 +225,22 @@
</Chord>
</voice>
<voice>
<location>
<fractions>1/4</fractions>
</location>
<location>
<fractions>1/4</fractions>
</location>
<location>
<fractions>1/4</fractions>
</location>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
</voice>
</Measure>
</Staff>
Expand Down
25 changes: 16 additions & 9 deletions src/importexport/guitarpro/tests/data/fade-in.gpx-ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,22 @@
</Rest>
</voice>
<voice>
<location>
<fractions>1/4</fractions>
</location>
<location>
<fractions>1/4</fractions>
</location>
<location>
<fractions>1/4</fractions>
</location>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
<Rest>
<visible>0</visible>
<durationType>quarter</durationType>
</Rest>
</voice>
</Measure>
</Staff>
Expand Down
Loading