Skip to content

Commit

Permalink
fix: gp7 rse import
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekirin committed Mar 10, 2025
1 parent b6fb64f commit 5e0e456
Show file tree
Hide file tree
Showing 15 changed files with 7,317 additions and 64 deletions.
99 changes: 90 additions & 9 deletions src/importexport/guitarpro/internal/gtp/gp7dombuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,71 @@

using namespace muse;

namespace {
std::map<String, int> RSE2MidiProgram = {
// Acoustic Guitars
{ u"Stringed/Acoustic Guitars/Steel Guitar", 25 },
{ u"Stringed/Acoustic Guitars/12 String Steel", 25 },
{ u"Stringed/Acoustic Guitars/Nylon Guitar", 24 },
{ u"Stringed/Acoustic Guitars/Resonator", 25 },
// Electric Guitars
{ u"Stringed/Electric Guitars/Clean Guitar", 27 },
{ u"Stringed/Electric Guitars/Jazz Guitar", 26 },
{ u"Stringed/Electric Guitars/12 Strings Electric Guitar", 27 },
{ u"Stringed/Electric Guitars/Overdrive Guitar", 29 },
{ u"Stringed/Electric Guitars/Distortion Guitar", 30 },
{ u"Stringed/Electric Guitars/Electric Sitar", 104 },
// Bass Guitars
{ u"Stringed/Basses/Clean Bass", 33 },
{ u"Stringed/Basses/Slap Bass", 37 },
{ u"Stringed/Basses/Crunch Bass", 33 },
{ u"Stringed/Basses/Acoustic Bass", 32 },
{ u"Stringed/Basses/Fretless Bass", 35 },
{ u"Stringed/Basses/Upright Bass", 32 },
{ u"Stringed/Basses/Synth Bass", 39 },
// Other Stringed instruments
{ u"Stringed/Other Stringed Instruments/Ukulele", 24 },
{ u"Stringed/Other Stringed Instruments/Banjo", 105 },
{ u"Stringed/Other Stringed Instruments/Mandolin", 25 },
{ u"Stringed/Other Stringed Instruments/Pedal Steel", 26 },
// Keyboard
{ u"Orchestra/Keyboard/Acoustic Piano", 1 },
{ u"Orchestra/Keyboard/Electric Piano", 4 },
{ u"Orchestra/Keyboard/Organ", 16 },
{ u"Orchestra/Keyboard/Clavinet", 6 },
{ u"Orchestra/Keyboard/Accordion", 21 },
// Synth
{ u"Orchestra/Synth/Brass", 62 },
{ u"Orchestra/Synth/Keyboard", 98 },
{ u"Orchestra/Synth/Lead", 87 },
{ u"Orchestra/Synth/Bass", 38 },
{ u"Orchestra/Synth/Pad", 90 },
{ u"Orchestra/Synth/Sequencer", 99 },
// Strings
{ u"Orchestra/Strings/Violin", 40 },
{ u"Orchestra/Strings/Viola", 41 },
{ u"Orchestra/Strings/Cello", 42 },
{ u"Orchestra/Strings/Contrabass", 43 },
{ u"Orchestra/Strings/Harp", 46 },
// Winds
{ u"Orchestra/Winds/Harmonica", 22 },
{ u"Orchestra/Winds/Trumpet", 56 },
{ u"Orchestra/Winds/Trombone", 57 },
{ u"Orchestra/Winds/Tuba", 58 },
{ u"Orchestra/Winds/Saxophone", 65 },
{ u"Orchestra/Winds/Clarinet", 71 },
{ u"Orchestra/Winds/Bassoon", 70 },
{ u"Orchestra/Winds/Flute", 73 },
{ u"Orchestra/Winds/Other Winds", 74 },
// Other Instruments
{ u"Orchestra/Other/Celesta", 8 },
{ u"Orchestra/Other/Vibraphone", 11 },
{ u"Orchestra/Other/Xylophone", 13 },
{ u"Orchestra/Other/Singer", 52 },
{ u"Orchestra/Other/Timpani", 47 },
};
}

namespace mu::iex::guitarpro {
std::pair<int, std::unique_ptr<GPTrack> > GP7DomBuilder::createGPTrack(XmlDomNode* trackNode, XmlDomNode* versionNode)
{
Expand All @@ -21,6 +86,7 @@ std::pair<int, std::unique_ptr<GPTrack> > GP7DomBuilder::createGPTrack(XmlDomNod
auto track = std::make_unique<GPTrack>(trackIdx);
XmlDomNode trackChildNode = trackNode->firstChild();
String version = versionNode->toElement().text();
bool isRSE = u"RSE" == trackNode->firstChildElement("AudioEngineState").text();

while (!trackChildNode.isNull()) {
String nodeName = trackChildNode.nodeName();
Expand All @@ -35,10 +101,11 @@ std::pair<int, std::unique_ptr<GPTrack> > GP7DomBuilder::createGPTrack(XmlDomNod
} else if (nodeName == u"ShortName") {
track->setShortName(trackChildNode.toElement().text());
} else if (nodeName == u"Sounds") {
int programm = readMidiProgramm(&trackChildNode);
String firstSoundPath = trackChildNode.firstChild().firstChildElement("Path").text();
int programm = readMidiProgramm(&trackChildNode, isRSE, firstSoundPath);
auto soundNode = trackChildNode.firstChild();
while (!soundNode.isNull()) {
GPTrack::Sound sound = readSounds(&soundNode);
GPTrack::Sound sound = readSounds(&soundNode, isRSE);
track->addSound(sound);

soundNode = soundNode.nextSibling();
Expand Down Expand Up @@ -100,26 +167,40 @@ int GP7DomBuilder::readMidiChannel(XmlDomNode* trackChildNode) const
return channel;
}

int GP7DomBuilder::readMidiProgramm(XmlDomNode* trackChildNode) const
int GP7DomBuilder::readMidiProgramm(XmlDomNode* trackChildNode, bool isRSE, const String& soundPath) const
{
int programm = trackChildNode->firstChild()
.firstChildElement("MIDI")
.firstChildElement("Program")
.text().toInt();
if (isRSE) {
if (auto it = RSE2MidiProgram.find(soundPath); it != RSE2MidiProgram.end()) {
programm = it->second;
}
}

return programm;
}

GPTrack::Sound GP7DomBuilder::readSounds(XmlDomNode* soundNode) const
GPTrack::Sound GP7DomBuilder::readSounds(XmlDomNode* soundNode, bool isRSE) const
{
GPTrack::Sound result;

result.programm = soundNode->firstChildElement("MIDI")
.firstChildElement("Program")
.text().toInt();
result.path = soundNode->firstChildElement("Path").text();
if (isRSE) {
if (auto it = RSE2MidiProgram.find(result.path); it != RSE2MidiProgram.end()) {
result.programm = it->second;
} else {
result.programm = soundNode->firstChildElement("MIDI")
.firstChildElement("Program")
.text().toInt();
}
} else {
result.programm = soundNode->firstChildElement("MIDI")
.firstChildElement("Program")
.text().toInt();
}
result.name = soundNode->firstChildElement("Name").text();
result.label = soundNode->firstChildElement("Label").text();
result.path = soundNode->firstChildElement("Path").text();
result.role = soundNode->firstChildElement("Role").text();

return result;
Expand Down
4 changes: 2 additions & 2 deletions src/importexport/guitarpro/internal/gtp/gp7dombuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class GP7DomBuilder : public GP67DomBuilder
std::pair<int, std::unique_ptr<GPTrack> > createGPTrack(muse::XmlDomNode* trackNode, muse::XmlDomNode* versionNode) override;

int readMidiChannel(muse::XmlDomNode* trackChildNode) const;
int readMidiProgramm(muse::XmlDomNode* trackChildNode) const;
GPTrack::Sound readSounds(muse::XmlDomNode* trackChildNode) const;
int readMidiProgramm(muse::XmlDomNode* trackChildNode, bool isRSE, const muse::String& soundPath) const;
GPTrack::Sound readSounds(muse::XmlDomNode* trackChildNode, bool isRSE) const;
GPTrack::SoundAutomation readTrackAutomation(muse::XmlDomNode* automationNode) const;
};
} // namespace mu::iex::guitarpro
Expand Down
7 changes: 6 additions & 1 deletion src/importexport/guitarpro/internal/gtp/gpconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,12 @@ void GPConverter::addInstrumentChanges()
auto it = track.second->sounds().find(soundAutomation.second.value);
if (it == track.second->sounds().end()) {
midiProgramm = track.second->programm();
instrName = soundAutomation.second.value;
engraving::StringList list = soundAutomation.second.value.split(';');
if (list.size() != 1) {
instrName = list[0].split('/')[2]; // Always looks like 'Main Group/Instrument Group/Instrument'
} else {
instrName = soundAutomation.second.value;
}
} else {
midiProgramm = it->second.programm;
instrName = it->second.label;
Expand Down
2 changes: 1 addition & 1 deletion src/importexport/guitarpro/internal/gtp/gptrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace mu::iex::guitarpro {
void GPTrack::addSound(Sound sound)
{
muse::String key = sound.path + u";" + sound.name + u";" + sound.role;
muse::String key = sound.path;

_sounds.insert({ key, sound });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<string>64</string>
</StringData>
<Channel>
<program value="0"/>
<program value="1"/>
<controller ctrl="7" value="101"/>
<midiPort>0</midiPort>
<midiChannel>2</midiChannel>
Expand Down
2 changes: 1 addition & 1 deletion src/importexport/guitarpro/tests/data/clefs.gp-ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<string>64</string>
</StringData>
<Channel>
<program value="0"/>
<program value="1"/>
<controller ctrl="7" value="101"/>
<midiPort>0</midiPort>
<midiChannel>2</midiChannel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
</StaffType>
</Staff>
<trackName>Bells</trackName>
<Instrument id="xylomarimba">
<Instrument id="xylophone">
<longName>Bells</longName>
<shortName>mar.</shortName>
<trackName></trackName>
<transposeDiatonic>7</transposeDiatonic>
<transposeChromatic>12</transposeChromatic>
<instrumentId>pitched-percussion.xylomarimba</instrumentId>
<instrumentId>pitched-percussion.xylophone</instrumentId>
<singleNoteDynamics>0</singleNoteDynamics>
<StringData>
<frets>24</frets>
Expand All @@ -41,7 +41,7 @@
<string>52</string>
</StringData>
<Channel>
<program value="12"/>
<program value="13"/>
<controller ctrl="7" value="71"/>
</Channel>
</Instrument>
Expand Down
6 changes: 3 additions & 3 deletions src/importexport/guitarpro/tests/data/grace.gp-ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
</StaffType>
</Staff>
<trackName>E. Guitar 2</trackName>
<Instrument id="grand-piano">
<Instrument id="piano">
<longName>E. Guitar 2</longName>
<shortName>pno.</shortName>
<trackName></trackName>
<instrumentId>keyboard.piano.grand</instrumentId>
<instrumentId>keyboard.piano</instrumentId>
<singleNoteDynamics>0</singleNoteDynamics>
<StringData>
<frets>24</frets>
Expand All @@ -39,7 +39,7 @@
<string>64</string>
</StringData>
<Channel>
<program value="0"/>
<program value="1"/>
<controller ctrl="7" value="74"/>
</Channel>
</Instrument>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,27 +86,6 @@ The Wall</text>
<tempo>1.916667</tempo>
<text><sym>metNoteQuarterUp</sym> = 115</text>
</Tempo>
<InstrumentChange>
<Instrument id="grand-piano">
<trackName></trackName>
<transposeDiatonic>-7</transposeDiatonic>
<transposeChromatic>-12</transposeChromatic>
<instrumentId>keyboard.piano.grand</instrumentId>
<StringData>
<frets>24</frets>
<string>76</string>
<string>69</string>
<string>74</string>
<string>79</string>
<string>71</string>
<string>76</string>
</StringData>
<Channel>
<program value="0"/>
</Channel>
</Instrument>
<text>Acoustic Grand Piano</text>
</InstrumentChange>
<Chord>
<durationType>half</durationType>
<Note>
Expand Down
Loading

0 comments on commit 5e0e456

Please sign in to comment.