Skip to content

Commit 5291070

Browse files
authored
fix: gp7 rse import (#26956)
1 parent bb695f0 commit 5291070

13 files changed

+7298
-24
lines changed

src/importexport/guitarpro/internal/gtp/gp7dombuilder.cpp

Lines changed: 90 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,71 @@
66

77
using namespace muse;
88

9+
namespace {
10+
std::map<String, int> RSE2MidiProgram = {
11+
// Acoustic Guitars
12+
{ u"Stringed/Acoustic Guitars/Steel Guitar", 25 },
13+
{ u"Stringed/Acoustic Guitars/12 String Steel", 25 },
14+
{ u"Stringed/Acoustic Guitars/Nylon Guitar", 24 },
15+
{ u"Stringed/Acoustic Guitars/Resonator", 25 },
16+
// Electric Guitars
17+
{ u"Stringed/Electric Guitars/Clean Guitar", 27 },
18+
{ u"Stringed/Electric Guitars/Jazz Guitar", 26 },
19+
{ u"Stringed/Electric Guitars/12 Strings Electric Guitar", 27 },
20+
{ u"Stringed/Electric Guitars/Overdrive Guitar", 29 },
21+
{ u"Stringed/Electric Guitars/Distortion Guitar", 30 },
22+
{ u"Stringed/Electric Guitars/Electric Sitar", 104 },
23+
// Bass Guitars
24+
{ u"Stringed/Basses/Clean Bass", 33 },
25+
{ u"Stringed/Basses/Slap Bass", 37 },
26+
{ u"Stringed/Basses/Crunch Bass", 33 },
27+
{ u"Stringed/Basses/Acoustic Bass", 32 },
28+
{ u"Stringed/Basses/Fretless Bass", 35 },
29+
{ u"Stringed/Basses/Upright Bass", 32 },
30+
{ u"Stringed/Basses/Synth Bass", 39 },
31+
// Other Stringed instruments
32+
{ u"Stringed/Other Stringed Instruments/Ukulele", 24 },
33+
{ u"Stringed/Other Stringed Instruments/Banjo", 105 },
34+
{ u"Stringed/Other Stringed Instruments/Mandolin", 25 },
35+
{ u"Stringed/Other Stringed Instruments/Pedal Steel", 26 },
36+
// Keyboard
37+
{ u"Orchestra/Keyboard/Acoustic Piano", 1 },
38+
{ u"Orchestra/Keyboard/Electric Piano", 4 },
39+
{ u"Orchestra/Keyboard/Organ", 16 },
40+
{ u"Orchestra/Keyboard/Clavinet", 6 },
41+
{ u"Orchestra/Keyboard/Accordion", 21 },
42+
// Synth
43+
{ u"Orchestra/Synth/Brass", 62 },
44+
{ u"Orchestra/Synth/Keyboard", 98 },
45+
{ u"Orchestra/Synth/Lead", 87 },
46+
{ u"Orchestra/Synth/Bass", 38 },
47+
{ u"Orchestra/Synth/Pad", 90 },
48+
{ u"Orchestra/Synth/Sequencer", 99 },
49+
// Strings
50+
{ u"Orchestra/Strings/Violin", 40 },
51+
{ u"Orchestra/Strings/Viola", 41 },
52+
{ u"Orchestra/Strings/Cello", 42 },
53+
{ u"Orchestra/Strings/Contrabass", 43 },
54+
{ u"Orchestra/Strings/Harp", 46 },
55+
// Winds
56+
{ u"Orchestra/Winds/Harmonica", 22 },
57+
{ u"Orchestra/Winds/Trumpet", 56 },
58+
{ u"Orchestra/Winds/Trombone", 57 },
59+
{ u"Orchestra/Winds/Tuba", 58 },
60+
{ u"Orchestra/Winds/Saxophone", 65 },
61+
{ u"Orchestra/Winds/Clarinet", 71 },
62+
{ u"Orchestra/Winds/Bassoon", 70 },
63+
{ u"Orchestra/Winds/Flute", 73 },
64+
{ u"Orchestra/Winds/Other Winds", 74 },
65+
// Other Instruments
66+
{ u"Orchestra/Other/Celesta", 8 },
67+
{ u"Orchestra/Other/Vibraphone", 11 },
68+
{ u"Orchestra/Other/Xylophone", 13 },
69+
{ u"Orchestra/Other/Singer", 52 },
70+
{ u"Orchestra/Other/Timpani", 47 },
71+
};
72+
}
73+
974
namespace mu::iex::guitarpro {
1075
std::pair<int, std::unique_ptr<GPTrack> > GP7DomBuilder::createGPTrack(XmlDomNode* trackNode, XmlDomNode* versionNode)
1176
{
@@ -21,6 +86,7 @@ std::pair<int, std::unique_ptr<GPTrack> > GP7DomBuilder::createGPTrack(XmlDomNod
2186
auto track = std::make_unique<GPTrack>(trackIdx);
2287
XmlDomNode trackChildNode = trackNode->firstChild();
2388
String version = versionNode->toElement().text();
89+
bool isRSE = u"RSE" == trackNode->firstChildElement("AudioEngineState").text();
2490

2591
while (!trackChildNode.isNull()) {
2692
String nodeName = trackChildNode.nodeName();
@@ -35,10 +101,11 @@ std::pair<int, std::unique_ptr<GPTrack> > GP7DomBuilder::createGPTrack(XmlDomNod
35101
} else if (nodeName == u"ShortName") {
36102
track->setShortName(trackChildNode.toElement().text());
37103
} else if (nodeName == u"Sounds") {
38-
int programm = readMidiProgramm(&trackChildNode);
104+
String firstSoundPath = trackChildNode.firstChild().firstChildElement("Path").text();
105+
int programm = readMidiProgramm(&trackChildNode, isRSE, firstSoundPath);
39106
auto soundNode = trackChildNode.firstChild();
40107
while (!soundNode.isNull()) {
41-
GPTrack::Sound sound = readSounds(&soundNode);
108+
GPTrack::Sound sound = readSounds(&soundNode, isRSE);
42109
track->addSound(sound);
43110

44111
soundNode = soundNode.nextSibling();
@@ -100,26 +167,40 @@ int GP7DomBuilder::readMidiChannel(XmlDomNode* trackChildNode) const
100167
return channel;
101168
}
102169

103-
int GP7DomBuilder::readMidiProgramm(XmlDomNode* trackChildNode) const
170+
int GP7DomBuilder::readMidiProgramm(XmlDomNode* trackChildNode, bool isRSE, const String& soundPath) const
104171
{
105172
int programm = trackChildNode->firstChild()
106173
.firstChildElement("MIDI")
107174
.firstChildElement("Program")
108175
.text().toInt();
176+
if (isRSE) {
177+
if (auto it = RSE2MidiProgram.find(soundPath); it != RSE2MidiProgram.end()) {
178+
programm = it->second;
179+
}
180+
}
109181

110182
return programm;
111183
}
112184

113-
GPTrack::Sound GP7DomBuilder::readSounds(XmlDomNode* soundNode) const
185+
GPTrack::Sound GP7DomBuilder::readSounds(XmlDomNode* soundNode, bool isRSE) const
114186
{
115187
GPTrack::Sound result;
116-
117-
result.programm = soundNode->firstChildElement("MIDI")
118-
.firstChildElement("Program")
119-
.text().toInt();
188+
result.path = soundNode->firstChildElement("Path").text();
189+
if (isRSE) {
190+
if (auto it = RSE2MidiProgram.find(result.path); it != RSE2MidiProgram.end()) {
191+
result.programm = it->second;
192+
} else {
193+
result.programm = soundNode->firstChildElement("MIDI")
194+
.firstChildElement("Program")
195+
.text().toInt();
196+
}
197+
} else {
198+
result.programm = soundNode->firstChildElement("MIDI")
199+
.firstChildElement("Program")
200+
.text().toInt();
201+
}
120202
result.name = soundNode->firstChildElement("Name").text();
121203
result.label = soundNode->firstChildElement("Label").text();
122-
result.path = soundNode->firstChildElement("Path").text();
123204
result.role = soundNode->firstChildElement("Role").text();
124205

125206
return result;

src/importexport/guitarpro/internal/gtp/gp7dombuilder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class GP7DomBuilder : public GP67DomBuilder
1414
std::pair<int, std::unique_ptr<GPTrack> > createGPTrack(muse::XmlDomNode* trackNode, muse::XmlDomNode* versionNode) override;
1515

1616
int readMidiChannel(muse::XmlDomNode* trackChildNode) const;
17-
int readMidiProgramm(muse::XmlDomNode* trackChildNode) const;
18-
GPTrack::Sound readSounds(muse::XmlDomNode* trackChildNode) const;
17+
int readMidiProgramm(muse::XmlDomNode* trackChildNode, bool isRSE, const muse::String& soundPath) const;
18+
GPTrack::Sound readSounds(muse::XmlDomNode* trackChildNode, bool isRSE) const;
1919
GPTrack::SoundAutomation readTrackAutomation(muse::XmlDomNode* automationNode) const;
2020
};
2121
} // namespace mu::iex::guitarpro

src/importexport/guitarpro/internal/gtp/gpconverter.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,10 +1546,15 @@ void GPConverter::addInstrumentChanges()
15461546
int midiProgramm = 0;
15471547
String instrName;
15481548

1549-
auto it = track.second->sounds().find(soundAutomation.second.value);
1549+
auto it = track.second->sounds().find(soundAutomation.second.value.split(';').at(0));
15501550
if (it == track.second->sounds().end()) {
15511551
midiProgramm = track.second->programm();
1552-
instrName = soundAutomation.second.value;
1552+
engraving::StringList list = soundAutomation.second.value.split(';');
1553+
if (list.size() != 1) {
1554+
instrName = list[0].split('/')[2]; // Always looks like 'Main Group/Instrument Group/Instrument'
1555+
} else {
1556+
instrName = soundAutomation.second.value;
1557+
}
15531558
} else {
15541559
midiProgramm = it->second.programm;
15551560
instrName = it->second.label;

src/importexport/guitarpro/internal/gtp/gptrack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace mu::iex::guitarpro {
44
void GPTrack::addSound(Sound sound)
55
{
6-
muse::String key = sound.path + u";" + sound.name + u";" + sound.role;
6+
muse::String key = sound.path;
77

88
_sounds.insert({ key, sound });
99
}

src/importexport/guitarpro/tests/data/chordnames_keyboard.gp-ref.mscx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<string>64</string>
4848
</StringData>
4949
<Channel>
50-
<program value="0"/>
50+
<program value="1"/>
5151
<controller ctrl="7" value="101"/>
5252
<midiPort>0</midiPort>
5353
<midiChannel>2</midiChannel>

src/importexport/guitarpro/tests/data/clefs.gp-ref.mscx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<string>64</string>
4040
</StringData>
4141
<Channel>
42-
<program value="0"/>
42+
<program value="1"/>
4343
<controller ctrl="7" value="101"/>
4444
<midiPort>0</midiPort>
4545
<midiChannel>2</midiChannel>

src/importexport/guitarpro/tests/data/dotted-tuplets.gp-ref.mscx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
</StaffType>
2424
</Staff>
2525
<trackName>Bells</trackName>
26-
<Instrument id="xylomarimba">
26+
<Instrument id="xylophone">
2727
<longName>Bells</longName>
2828
<shortName>mar.</shortName>
2929
<trackName></trackName>
3030
<transposeDiatonic>7</transposeDiatonic>
3131
<transposeChromatic>12</transposeChromatic>
32-
<instrumentId>pitched-percussion.xylomarimba</instrumentId>
32+
<instrumentId>pitched-percussion.xylophone</instrumentId>
3333
<singleNoteDynamics>0</singleNoteDynamics>
3434
<StringData>
3535
<frets>24</frets>
@@ -41,7 +41,7 @@
4141
<string>52</string>
4242
</StringData>
4343
<Channel>
44-
<program value="12"/>
44+
<program value="13"/>
4545
<controller ctrl="7" value="71"/>
4646
</Channel>
4747
</Instrument>

src/importexport/guitarpro/tests/data/grace.gp-ref.mscx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
</StaffType>
2424
</Staff>
2525
<trackName>E. Guitar 2</trackName>
26-
<Instrument id="grand-piano">
26+
<Instrument id="piano">
2727
<longName>E. Guitar 2</longName>
2828
<shortName>pno.</shortName>
2929
<trackName></trackName>
30-
<instrumentId>keyboard.piano.grand</instrumentId>
30+
<instrumentId>keyboard.piano</instrumentId>
3131
<singleNoteDynamics>0</singleNoteDynamics>
3232
<StringData>
3333
<frets>24</frets>
@@ -39,7 +39,7 @@
3939
<string>64</string>
4040
</StringData>
4141
<Channel>
42-
<program value="0"/>
42+
<program value="1"/>
4343
<controller ctrl="7" value="74"/>
4444
</Channel>
4545
</Instrument>
14.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)