Skip to content

Commit b99f56e

Browse files
committed
Import left hand fingerings from .gp files.
The thumb is not supported, which is probably something we should add to our file format. #290
1 parent 06f1248 commit b99f56e

File tree

5 files changed

+96
-1
lines changed

5 files changed

+96
-1
lines changed

source/formats/gp7/converter.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <formats/fileformat.h>
2525
#include <score/keysignature.h>
26+
#include <score/note.h>
2627
#include <score/playerchange.h>
2728
#include <score/position.h>
2829
#include <score/rehearsalsign.h>
@@ -209,6 +210,37 @@ convertNote(Position &position, const Gp7::Beat &gp_beat,
209210
tuning.getNote(note.getString(), false));
210211
}
211212

213+
if (gp_note.myLeftFinger)
214+
{
215+
using FingerType = Gp7::Note::FingerType;
216+
switch (*gp_note.myLeftFinger)
217+
{
218+
case FingerType::Open:
219+
note.setLeftHandFingering(
220+
LeftHandFingering(LeftHandFingering::None));
221+
break;
222+
case FingerType::C:
223+
note.setLeftHandFingering(
224+
LeftHandFingering(LeftHandFingering::Little));
225+
break;
226+
case FingerType::A:
227+
note.setLeftHandFingering(
228+
LeftHandFingering(LeftHandFingering::Ring));
229+
break;
230+
case FingerType::M:
231+
note.setLeftHandFingering(
232+
LeftHandFingering(LeftHandFingering::Middle));
233+
break;
234+
case FingerType::I:
235+
note.setLeftHandFingering(
236+
LeftHandFingering(LeftHandFingering::Index));
237+
break;
238+
case FingerType::P:
239+
// TODO - thumb is not currently support for fingerings.
240+
break;
241+
}
242+
}
243+
212244
return note;
213245
}
214246

source/formats/gp7/parser.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,28 @@ parseNotes(const pugi::xml_node &notes_node)
471471
if (node.child("LetRing"))
472472
note.myLetRing = true;
473473

474-
// TODO - import bends and left hand fingerings.
474+
if (auto fingering = node.child("LeftFingering"))
475+
{
476+
using FingerType = Gp7::Note::FingerType;
477+
478+
std::string_view text = fingering.text().as_string();
479+
if (text == "Open")
480+
note.myLeftFinger = FingerType::Open;
481+
else if (text == "C")
482+
note.myLeftFinger = FingerType::C;
483+
else if (text == "A")
484+
note.myLeftFinger = FingerType::A;
485+
else if (text == "M")
486+
note.myLeftFinger = FingerType::M;
487+
else if (text == "I")
488+
note.myLeftFinger = FingerType::I;
489+
else if (text == "P")
490+
note.myLeftFinger = FingerType::P;
491+
else
492+
throw FileFormatException("Unexpected finger type.");
493+
}
494+
495+
// TODO - import bends.
475496

476497
const int id = node.attribute("id").as_int();
477498
notes.emplace(id, note);

source/formats/gp7/parser.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,16 @@ struct Note
230230
NumTypes
231231
};
232232

233+
enum class FingerType
234+
{
235+
Open,
236+
C,
237+
A,
238+
M,
239+
I,
240+
P
241+
};
242+
233243
int myString = 0;
234244
int myFret = 0;
235245
bool myPalmMuted = false;
@@ -249,6 +259,7 @@ struct Note
249259
/// Flags for various combinations of slide types.
250260
std::bitset<size_t(SlideType::NumTypes)> mySlideTypes;
251261
std::optional<int> myTrillNote;
262+
std::optional<FingerType> myLeftFinger;
252263
};
253264

254265
/// Container for a Guitar Pro 7 document.

test/formats/gp7/data/notes.gp

35 Bytes
Binary file not shown.

test/formats/gp7/test_gp7.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <formats/gp7/gp7importer.h>
2222
#include <score/generalmidi.h>
2323
#include <score/keysignature.h>
24+
#include <score/note.h>
2425
#include <score/playerchange.h>
2526
#include <score/score.h>
2627
#include <score/scoreinfo.h>
@@ -206,6 +207,7 @@ TEST_CASE("Formats/Gp7Import/Notes", "")
206207
REQUIRE(!note.hasArtificialHarmonic());
207208
REQUIRE(!note.hasTappedHarmonic());
208209
REQUIRE(!note.hasTrill());
210+
REQUIRE(!note.hasLeftHandFingering());
209211
}
210212

211213
{
@@ -295,6 +297,13 @@ TEST_CASE("Formats/Gp7Import/Notes", "")
295297
REQUIRE(note.hasProperty(Note::SlideOutOfUpwards));
296298
}
297299

300+
{
301+
const Note &note = voice.getPositions()[14].getNotes()[0];
302+
REQUIRE(note.hasLeftHandFingering());
303+
REQUIRE(note.getLeftHandFingering().getFingerNumber() ==
304+
LeftHandFingering::None);
305+
}
306+
298307
const Voice &voice2 = score.getSystems()[1].getStaves()[0].getVoices()[0];
299308
{
300309
const Note &note = voice2.getPositions()[0].getNotes()[0];
@@ -305,11 +314,31 @@ TEST_CASE("Formats/Gp7Import/Notes", "")
305314
{
306315
const Note &note = voice2.getPositions()[1].getNotes()[0];
307316
REQUIRE(note.hasProperty(Note::LegatoSlide));
317+
REQUIRE(note.hasLeftHandFingering());
318+
REQUIRE(note.getLeftHandFingering().getFingerNumber() ==
319+
LeftHandFingering::Little);
308320
}
309321

310322
{
311323
const Note &note = voice2.getPositions()[2].getNotes()[0];
312324
REQUIRE(note.hasProperty(Note::ShiftSlide));
325+
REQUIRE(note.hasLeftHandFingering());
326+
REQUIRE(note.getLeftHandFingering().getFingerNumber() ==
327+
LeftHandFingering::Ring);
328+
}
329+
330+
{
331+
const Note &note = voice2.getPositions()[3].getNotes()[0];
332+
REQUIRE(note.hasLeftHandFingering());
333+
REQUIRE(note.getLeftHandFingering().getFingerNumber() ==
334+
LeftHandFingering::Middle);
335+
}
336+
337+
{
338+
const Note &note = voice2.getPositions()[4].getNotes()[0];
339+
REQUIRE(note.hasLeftHandFingering());
340+
REQUIRE(note.getLeftHandFingering().getFingerNumber() ==
341+
LeftHandFingering::Index);
313342
}
314343

315344
{
@@ -322,6 +351,8 @@ TEST_CASE("Formats/Gp7Import/Notes", "")
322351
const Position &pos = voice2.getPositions()[6];
323352
REQUIRE(pos.hasProperty(Position::Acciaccatura));
324353
REQUIRE(pos.hasProperty(Position::PickStrokeDown));
354+
// Left hand fingerings currently don't support thumbs.
355+
REQUIRE(!pos.getNotes()[0].hasLeftHandFingering());
325356
}
326357

327358
{

0 commit comments

Comments
 (0)