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

fix: gp7 rse import #26956

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
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
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
Loading