Skip to content

Commit be3172b

Browse files
authored
Merge pull request #34303 from alexpavlov96/import_dives
Import dives: phase 1
2 parents f2e0b9e + a6b4342 commit be3172b

36 files changed

Lines changed: 1755 additions & 184 deletions

src/importexport/guitarpro/CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,16 @@ target_sources(iex_guitarpro PRIVATE
4747
internal/guitarbendimport/guitarbendimporttypes.h
4848
internal/guitarbendimport/guitarbendimporter.cpp
4949
internal/guitarbendimport/guitarbendimporter.h
50-
internal/guitarbendimport/benddatacontext.h
5150
internal/guitarbendimport/benddatacollector.cpp
5251
internal/guitarbendimport/benddatacollector.h
5352
internal/guitarbendimport/bendinfoconverter.cpp
5453
internal/guitarbendimport/bendinfoconverter.h
55-
internal/guitarbendimport/benddataprocessor.cpp
56-
internal/guitarbendimport/benddataprocessor.h
54+
internal/guitarbendimport/bendbuilder.cpp
55+
internal/guitarbendimport/bendbuilder.h
56+
internal/guitarbendimport/diveinfoconverter.cpp
57+
internal/guitarbendimport/diveinfoconverter.h
58+
internal/guitarbendimport/divedatacollector.cpp
59+
internal/guitarbendimport/divedatacollector.h
5760

5861
internal/guitarbendimport/splitchord/benddatacontextsplitchord.h
5962
internal/guitarbendimport/splitchord/benddatacollectorsplitchord.cpp

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

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,7 @@ std::pair<int, std::shared_ptr<GPBeat> > GP67DomBuilder::createGPBeat(XmlDomNode
663663
} else if (nodeName == u"Ottavia") {
664664
beat->setOttavaType(ottavaType(innerNode.toElement().text()));
665665
} else if (nodeName == u"Whammy" || nodeName == u"WhammyExtend") {
666-
// TODO-gp: implement dives
667-
beat->setDive(true);
666+
beat->setWhammy(readWhammy(innerNode.toElement()));
668667
} else if (nodeName == u"DeadSlapped") {
669668
beat->setDeadSlapped(true);
670669
} else if (nodeName == u"TransposedPitchStemOrientation") {
@@ -1052,6 +1051,19 @@ void GP67DomBuilder::readBeatXProperties(const XmlDomNode& propertiesNode, GPBea
10521051
}
10531052
}
10541053

1054+
GPBeat::Whammy GP67DomBuilder::readWhammy(const XmlDomElement& elem) const
1055+
{
1056+
GPBeat::Whammy whammy;
1057+
whammy.originValue = elem.attribute("originValue").value().toFloat();
1058+
whammy.destinationValue = elem.attribute("destinationValue").value().toFloat();
1059+
whammy.middleValue = elem.attribute("middleValue").value().toFloat();
1060+
whammy.originOffset = elem.attribute("originOffset").value().toFloat();
1061+
whammy.middleOffset1 = elem.attribute("middleOffset1").value().toFloat();
1062+
whammy.middleOffset2 = elem.attribute("middleOffset2").value().toFloat();
1063+
whammy.destinationOffset = elem.attribute("destinationOffset").value().toFloat();
1064+
return whammy;
1065+
}
1066+
10551067
std::unique_ptr<GPNote::Bend> GP67DomBuilder::createBend(XmlDomNode* propertyNode)
10561068
{
10571069
std::unique_ptr<GPNote::Bend> bend = std::make_unique<GPNote::Bend>();
@@ -1174,6 +1186,8 @@ void GP67DomBuilder::readBeatProperties(const XmlDomNode& propertiesNode, GPBeat
11741186
return GPBeat::PickStroke::None;
11751187
};
11761188

1189+
GPBeat::Whammy whammyData;
1190+
bool hasWhammyMarker = false;
11771191
auto propertyNode = propertiesNode.firstChild();
11781192

11791193
while (!propertyNode.isNull()) {
@@ -1200,19 +1214,29 @@ void GP67DomBuilder::readBeatProperties(const XmlDomNode& propertiesNode, GPBeat
12001214
} else if (propertyName == u"BarreString") {
12011215
beat->setBarreString(propertyNode.firstChild().toElement().text().toInt());
12021216
} else if (propertyName == u"WhammyBar") {
1203-
beat->setDive(true);
1217+
hasWhammyMarker = true;
1218+
} else if (propertyName == u"WhammyBarOriginOffset") {
1219+
whammyData.originOffset = propertyNode.firstChild().toElement().text().toFloat();
1220+
} else if (propertyName == u"WhammyBarOriginValue") {
1221+
whammyData.originValue = propertyNode.firstChild().toElement().text().toFloat();
1222+
} else if (propertyName == u"WhammyBarDestinationValue") {
1223+
whammyData.destinationValue = propertyNode.firstChild().toElement().text().toFloat();
1224+
} else if (propertyName == u"WhammyBarMiddleValue") {
1225+
whammyData.middleValue = propertyNode.firstChild().toElement().text().toFloat();
1226+
} else if (propertyName == u"WhammyBarDestinationOffset") {
1227+
whammyData.destinationOffset = propertyNode.firstChild().toElement().text().toFloat();
1228+
} else if (propertyName == u"WhammyBarMiddleOffset1") {
1229+
whammyData.middleOffset1 = propertyNode.firstChild().toElement().text().toFloat();
1230+
} else if (propertyName == u"WhammyBarMiddleOffset2") {
1231+
whammyData.middleOffset2 = propertyNode.firstChild().toElement().text().toFloat();
12041232
}
1205-
/// TODO: implement dive
1206-
// else if (propertyName == u"WhammyBarDestinationOffset") {
1207-
// } else if (propertyName == u"WhammyBarDestinationValue") {
1208-
// } else if (propertyName == u"WhammyBarMiddleOffset1") {
1209-
// } else if (propertyName == u"WhammyBarMiddleOffset2") {
1210-
// } else if (propertyName == u"WhammyBarMiddleValue") {
1211-
// } else if (propertyName == u"WhammyBarOriginValue") {
1212-
// }
12131233

12141234
propertyNode = propertyNode.nextSibling();
12151235
}
1236+
1237+
if (hasWhammyMarker && !whammyData.isEmpty() && !beat->hasWhammy()) {
1238+
beat->setWhammy(whammyData);
1239+
}
12161240
}
12171241

12181242
void GP67DomBuilder::readTrackProperties(XmlDomNode* propertiesNode, GPTrack* track, bool ignoreTuningFlats) const

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class GP67DomBuilder : public IGPDomBuilder
4646
void readNoteProperties(muse::XmlDomNode* propertiesNode, GPNote* n);
4747
void readBeatXProperties(const muse::XmlDomNode& propertiesNode, GPBeat* b);
4848
std::unique_ptr<GPNote::Bend> createBend(muse::XmlDomNode* propertyNode);
49+
GPBeat::Whammy readWhammy(const muse::XmlDomElement& elem) const;
4950
void readHarmonic(muse::XmlDomNode* propertyNode, GPNote* note) const;
5051

5152
std::vector<GPMasterTracks::Automation> readTempoMap(muse::XmlDomNode* currentNode);

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class GPBeat
104104
}
105105
} comparePitch;
106106

107+
using Whammy = GPNote::Bend;
108+
107109
void addGPNote(const std::shared_ptr<GPNote>& n) { _notes.push_back(n); }
108110
void sortGPNotes();
109111
void addGPRhythm(const std::shared_ptr<GPRhythm>& n) { _rhythm = n; }
@@ -197,8 +199,9 @@ class GPBeat
197199
void setId(int id) { _id = id; }
198200
int id() const { return _id; }
199201

200-
void setDive(bool dive) { m_dive = dive; }
201-
bool dive() const { return m_dive; }
202+
void setWhammy(const Whammy& whammy) { m_whammy = whammy; }
203+
const Whammy& whammy() const { return m_whammy; }
204+
bool hasWhammy() const { return !m_whammy.isEmpty(); }
202205

203206
void setPickScrape(bool pickScrape) { m_pickScrape = pickScrape; }
204207
bool pickScrape() const { return m_pickScrape; }
@@ -302,7 +305,7 @@ class GPBeat
302305
Golpe m_golpe = Golpe::None;
303306
Barre _barre;
304307
double _arpeggioStretch = 0.0;
305-
bool m_dive = false; // TODO-gp: implement dives
308+
Whammy m_whammy;
306309
bool m_pickScrape = false;
307310
bool m_deadSlapped = false;
308311
StemOrientation m_stemOrientation;

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

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ void GPConverter::convert(const std::vector<std::unique_ptr<GPMasterBar> >& mast
345345

346346
addTempoMap();
347347
addInstrumentChanges();
348-
m_guitarBendImporter->applyBendsToChords();
348+
m_guitarBendImporter->addElementsToScore();
349349

350350
addFermatas();
351351
addContinuousSlideHammerOn();
@@ -1999,64 +1999,71 @@ void GPConverter::collectHammerOn(const GPNote* gpnote, Note* note)
19991999
}
20002000
}
20012001

2002-
void GPConverter::addBend(const GPNote* gpnote, Note* note)
2002+
static mu::engraving::PitchValues gpBendCurveToPitchValues(const GPNote::Bend& b)
20032003
{
2004-
if (!gpnote->bend() || gpnote->bend()->isEmpty()) {
2005-
return;
2006-
}
2007-
20082004
using namespace mu::engraving;
20092005

20102006
auto gpTimeToMuTime = [] (float time) {
20112007
return time * PitchValue::MAX_TIME / 100;
20122008
};
20132009

2014-
const GPNote::Bend* gpBend = gpnote->bend();
2015-
20162010
bool bendHasMiddleValue = true;
2017-
if (gpBend->middleOffset1 == 12 && gpBend->middleOffset2 == 12) {
2011+
if (b.middleOffset1 == 12 && b.middleOffset2 == 12) {
20182012
bendHasMiddleValue = false;
20192013
}
20202014

20212015
PitchValues pitchValues;
20222016

2023-
pitchValues.push_back(PitchValue(gpTimeToMuTime(gpBend->originOffset), gpBend->originValue));
2017+
pitchValues.push_back(PitchValue(gpTimeToMuTime(b.originOffset), b.originValue));
20242018
PitchValue lastPoint = pitchValues.back();
20252019

20262020
if (bendHasMiddleValue) {
2027-
if (PitchValue value(gpTimeToMuTime(gpBend->middleOffset1), gpBend->middleValue);
2028-
gpBend->middleOffset1 >= 0 && gpBend->middleOffset1 < gpBend->destinationOffset && value != lastPoint) {
2021+
if (PitchValue value(gpTimeToMuTime(b.middleOffset1), b.middleValue);
2022+
b.middleOffset1 >= 0 && b.middleOffset1 < b.destinationOffset && value != lastPoint) {
20292023
pitchValues.push_back(std::move(value));
20302024
}
20312025

2032-
if (PitchValue value(gpTimeToMuTime(gpBend->middleOffset2), gpBend->middleValue);
2033-
gpBend->middleOffset2 >= 0 && gpBend->middleOffset2 != gpBend->middleOffset1
2034-
&& gpBend->middleOffset2 < gpBend->destinationOffset
2026+
if (PitchValue value(gpTimeToMuTime(b.middleOffset2), b.middleValue);
2027+
b.middleOffset2 >= 0 && b.middleOffset2 != b.middleOffset1
2028+
&& b.middleOffset2 < b.destinationOffset
20352029
&& value != lastPoint) {
20362030
pitchValues.push_back(std::move(value));
20372031
}
20382032

2039-
if (gpBend->middleOffset1 == -1 && gpBend->middleOffset2 == -1 && gpBend->middleValue != -1) {
2033+
if (b.middleOffset1 == -1 && b.middleOffset2 == -1 && b.middleValue != -1) {
20402034
//!@NOTE It seems when middle point is places exactly in the middle
20412035
//!of bend GP6 stores this value equal -1
2042-
if (gpBend->destinationOffset > 50) {
2043-
pitchValues.push_back(PitchValue(gpTimeToMuTime(50), gpBend->middleValue));
2036+
if (b.destinationOffset > 50) {
2037+
pitchValues.push_back(PitchValue(gpTimeToMuTime(50), b.middleValue));
20442038
}
20452039
}
20462040
}
20472041

2048-
if (gpBend->destinationOffset <= 0) {
2049-
PitchValue fixGpxValue = PitchValue(gpTimeToMuTime(50), gpBend->middleValue);
2050-
if (gpBend->middleValue > gpBend->destinationValue && pitchValues.back() != fixGpxValue) {
2042+
if (b.destinationOffset <= 0) {
2043+
PitchValue fixGpxValue = PitchValue(gpTimeToMuTime(50), b.middleValue);
2044+
if (b.middleValue > b.destinationValue && pitchValues.back() != fixGpxValue) {
20512045
pitchValues.push_back(fixGpxValue);
20522046
}
2053-
pitchValues.push_back(PitchValue(gpTimeToMuTime(100), gpBend->destinationValue)); //! In .gpx this value might be exist
2047+
pitchValues.push_back(PitchValue(gpTimeToMuTime(100), b.destinationValue)); //! In .gpx this value might be exist
20542048
} else {
2055-
if (PitchValue value(gpTimeToMuTime(gpBend->destinationOffset), gpBend->destinationValue); value != lastPoint) {
2049+
if (PitchValue value(gpTimeToMuTime(b.destinationOffset), b.destinationValue); value != lastPoint) {
20562050
pitchValues.push_back(std::move(value));
20572051
}
20582052
}
20592053

2054+
return pitchValues;
2055+
}
2056+
2057+
void GPConverter::addBend(const GPNote* gpnote, Note* note)
2058+
{
2059+
if (!gpnote->bend() || gpnote->bend()->isEmpty()) {
2060+
return;
2061+
}
2062+
2063+
using namespace mu::engraving;
2064+
2065+
PitchValues pitchValues = gpBendCurveToPitchValues(*gpnote->bend());
2066+
20602067
if (pitchValues.size() < 2) {
20612068
return;
20622069
}
@@ -2355,7 +2362,13 @@ void GPConverter::addPalmMute(const GPBeat* gpbeat, ChordRest* cr)
23552362
void GPConverter::addDive(const GPBeat* beat, ChordRest* cr)
23562363
{
23572364
m_continiousElementsBuilder->buildContiniousElement(cr, ElementType::WHAMMY_BAR, ContiniousElementsBuilder::ImportType::WHAMMY_BAR,
2358-
beat->dive());
2365+
beat->hasWhammy());
2366+
2367+
if (!beat->hasWhammy() || !cr->isChord()) {
2368+
return;
2369+
}
2370+
2371+
m_guitarBendImporter->collectDive(toChord(cr), gpBendCurveToPitchValues(beat->whammy()));
23592372
}
23602373

23612374
void GPConverter::addPickScrape(const GPBeat* beat, ChordRest* cr)

0 commit comments

Comments
 (0)