Skip to content

Commit

Permalink
Merge pull request #25866 from alexpavlov96/guitarbend_import_part_1
Browse files Browse the repository at this point in the history
guitar bend import: part 1
  • Loading branch information
alexpavlov96 authored Dec 23, 2024
2 parents 6b965d4 + 1567613 commit 4648888
Show file tree
Hide file tree
Showing 39 changed files with 2,558 additions and 73 deletions.
1 change: 1 addition & 0 deletions src/appshell/view/preferences/noteinputpreferencesmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <QObject>

#include "async/asyncable.h"
#include "modularity/ioc.h"
#include "engraving/iengravingconfiguration.h"
#include "shortcuts/ishortcutsconfiguration.h"
Expand Down
7 changes: 1 addition & 6 deletions src/engraving/compat/midi/compatmidirenderinternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,12 +766,7 @@ static void collectNote(EventsHolder& events, const Note* note, const CollectNot
}

// Bends
if (note->configuration()->useStretchedBends()) {
if (const StretchedBend* stretchedBend = note->stretchedBend()) {
collectBend(stretchedBend->pitchValues(), stretchedBend->staffIdx(), noteChannel, tick1, tick1 + getPlayTicksForBend(
note).ticks(), pitchWheelRenderer, noteEffect);
}
} else if (bendFor) {
if (bendFor) {
collectGuitarBend(note, noteChannel, tick1, noteParams.graceOffsetOn, noteParams.previousChordTicks, pitchWheelRenderer,
noteEffect);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/engraving/dom/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ bool Measure::showsMeasureNumber()
/// Search for chord at position \a tick in \a track
//---------------------------------------------------------

Chord* Measure::findChord(Fraction t, track_idx_t track)
Chord* Measure::findChord(Fraction t, track_idx_t track) const
{
t -= tick();
for (Segment* seg = last(); seg; seg = seg->prev()) {
Expand All @@ -607,7 +607,7 @@ Chord* Measure::findChord(Fraction t, track_idx_t track)
/// Search for chord or rest at position \a tick at \a staff in \a voice.
//---------------------------------------------------------

ChordRest* Measure::findChordRest(Fraction t, track_idx_t track)
ChordRest* Measure::findChordRest(Fraction t, track_idx_t track) const
{
t -= tick();
for (const Segment& seg : m_segments) {
Expand Down
4 changes: 2 additions & 2 deletions src/engraving/dom/measure.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ class Measure final : public MeasureBase
bool showsMeasureNumber();
bool showsMeasureNumberInAutoMode();

Chord* findChord(Fraction tick, track_idx_t track);
ChordRest* findChordRest(Fraction tick, track_idx_t track);
Chord* findChord(Fraction tick, track_idx_t track) const;
ChordRest* findChordRest(Fraction tick, track_idx_t track) const;
Fraction snap(const Fraction& tick, const PointF p) const;
Fraction snapNote(const Fraction& tick, const PointF p, int staff) const;

Expand Down
3 changes: 2 additions & 1 deletion src/engraving/iengravingconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ class IEngravingConfiguration : MODULE_EXPORT_INTERFACE

/// these configurations will be removed after solving https://github.com/musescore/MuseScore/issues/14294
virtual bool guitarProImportExperimental() const = 0;
virtual bool useStretchedBends() const = 0;
virtual bool experimentalGuitarBendImport() const = 0;
virtual void setExperimentalGuitarBendImport(bool enabled) = 0;
virtual bool shouldAddParenthesisOnStandardStaff() const = 0;
virtual bool negativeFretsAllowed() const = 0;
virtual bool crossNoteHeadAlwaysBlack() const = 0;
Expand Down
11 changes: 9 additions & 2 deletions src/engraving/internal/engravingconfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ void EngravingConfiguration::init()
settings()->setDefaultValue(DO_NOT_SAVE_EIDS_FOR_BACK_COMPAT, Val(false));
settings()->setDescription(DO_NOT_SAVE_EIDS_FOR_BACK_COMPAT, muse::trc("engraving", "Do not save EIDs"));
settings()->setCanBeManuallyEdited(DO_NOT_SAVE_EIDS_FOR_BACK_COMPAT, false);

setExperimentalGuitarBendImport(guitarProImportExperimental());
}

muse::io::path_t EngravingConfiguration::appDataPath() const
Expand Down Expand Up @@ -388,9 +390,14 @@ bool EngravingConfiguration::guitarProImportExperimental() const
return guitarProConfiguration() ? guitarProConfiguration()->experimental() : false;
}

bool EngravingConfiguration::useStretchedBends() const
bool EngravingConfiguration::experimentalGuitarBendImport() const
{
return guitarProImportExperimental();
return m_experimentalGuitarBendImport;
}

void EngravingConfiguration::setExperimentalGuitarBendImport(bool enabled)
{
m_experimentalGuitarBendImport = enabled;
}

bool EngravingConfiguration::shouldAddParenthesisOnStandardStaff() const
Expand Down
4 changes: 3 additions & 1 deletion src/engraving/internal/engravingconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ class EngravingConfiguration : public IEngravingConfiguration, public muse::Inje
void setDoNotSaveEIDsForBackCompat(bool doNotSave) override;

bool guitarProImportExperimental() const override;
bool useStretchedBends() const override;
bool experimentalGuitarBendImport() const override;
void setExperimentalGuitarBendImport(bool enabled) override;
bool shouldAddParenthesisOnStandardStaff() const override;
bool negativeFretsAllowed() const override;
bool crossNoteHeadAlwaysBlack() const override;
Expand All @@ -126,6 +127,7 @@ class EngravingConfiguration : public IEngravingConfiguration, public muse::Inje
muse::ValNt<DebuggingOptions> m_debuggingOptions;

bool m_multiVoice = false;
bool m_experimentalGuitarBendImport = false;
};
}

Expand Down
20 changes: 0 additions & 20 deletions src/engraving/rendering/score/chordlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
#include "dom/staff.h"
#include "dom/stem.h"
#include "dom/stemslash.h"
#include "dom/stretchedbend.h"
#include "dom/system.h"
#include "dom/tie.h"
#include "dom/slur.h"
Expand Down Expand Up @@ -3078,25 +3077,6 @@ void ChordLayout::layoutChordBaseFingering(Chord* chord, System* system, LayoutC
}
}

void ChordLayout::layoutStretchedBends(Chord* chord, LayoutContext& ctx)
{
if (!chord->configuration()->useStretchedBends()) {
return;
}

for (EngravingItem* item : chord->el()) {
if (item && item->isStretchedBend()) {
toStretchedBend(item)->adjustBendInChord();
}
}

for (EngravingItem* item : chord->el()) {
if (item && item->isStretchedBend()) {
TLayout::layoutStretched(toStretchedBend(item), ctx);
}
}
}

void ChordLayout::crossMeasureSetup(Chord* chord, bool on, LayoutContext& ctx)
{
if (!on) {
Expand Down
1 change: 0 additions & 1 deletion src/engraving/rendering/score/chordlayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class ChordLayout
static void resolveRestVSRest(std::vector<Rest*>& rests, const Staff* staff, Segment* segment, LayoutContext& ctx,
bool considerBeams = false);
static void layoutChordBaseFingering(Chord* chord, System* system, LayoutContext& ctx);
static void layoutStretchedBends(Chord* chord, LayoutContext& ctx);

static void crossMeasureSetup(Chord* chord, bool on, LayoutContext& ctx);

Expand Down
1 change: 0 additions & 1 deletion src/engraving/rendering/score/systemlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,6 @@ void SystemLayout::layoutSystemElements(System* system, LayoutContext& ctx)
ChordLayout::layoutArticulations(c, ctx);
ChordLayout::layoutArticulations2(c, ctx);
ChordLayout::layoutChordBaseFingering(c, system, ctx);
ChordLayout::layoutStretchedBends(c, ctx);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/engraving/tests/mocks/engravingconfigurationmock.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ class EngravingConfigurationMock : public IEngravingConfiguration
MOCK_METHOD(void, setDoNotSaveEIDsForBackCompat, (bool), (override));

MOCK_METHOD(bool, guitarProImportExperimental, (), (const, override));
MOCK_METHOD(bool, useStretchedBends, (), (const, override));
MOCK_METHOD(bool, experimentalGuitarBendImport, (), (const, override));
MOCK_METHOD(void, setExperimentalGuitarBendImport, (bool), (override));
MOCK_METHOD(bool, shouldAddParenthesisOnStandardStaff, (), (const, override));
MOCK_METHOD(bool, negativeFretsAllowed, (), (const, override));
MOCK_METHOD(bool, crossNoteHeadAlwaysBlack, (), (const, override));
Expand Down
8 changes: 8 additions & 0 deletions src/importexport/guitarpro/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ set(MODULE_SRC
${CMAKE_CURRENT_LIST_DIR}/internal/utils.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/utils.h

${CMAKE_CURRENT_LIST_DIR}/internal/guitarbendimport/guitarbendimporter.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/guitarbendimport/guitarbendimporter.h
${CMAKE_CURRENT_LIST_DIR}/internal/guitarbendimport/benddatacontext.h
${CMAKE_CURRENT_LIST_DIR}/internal/guitarbendimport/benddatacollector.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/guitarbendimport/benddatacollector.h
${CMAKE_CURRENT_LIST_DIR}/internal/guitarbendimport/benddataprocessor.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/guitarbendimport/benddataprocessor.h

${CMAKE_CURRENT_LIST_DIR}/internal/gtp/gp6dombuilder.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/gtp/gp6dombuilder.h
${CMAKE_CURRENT_LIST_DIR}/internal/gtp/gp7dombuilder.cpp
Expand Down
21 changes: 9 additions & 12 deletions src/importexport/guitarpro/internal/gtp/gpconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include "engraving/dom/spanner.h"
#include "engraving/dom/staff.h"
#include "engraving/dom/stafftext.h"
#include "engraving/dom/stretchedbend.h"
#include "engraving/dom/tempotext.h"
#include "engraving/dom/text.h"
#include "engraving/dom/tie.h"
Expand Down Expand Up @@ -252,6 +251,10 @@ GPConverter::GPConverter(Score* score, std::unique_ptr<GPDomModel>&& gpDom, cons
_drumResolver = std::make_unique<GPDrumSetResolver>();
_drumResolver->initGPDrum();
m_continiousElementsBuilder = std::make_unique<ContiniousElementsBuilder>(_score);

if (engravingConfiguration()->experimentalGuitarBendImport()) {
m_guitarBendImporter = std::make_unique<GuitarBendImporter>(_score);
}
}

const std::unique_ptr<GPDomModel>& GPConverter::gpDom() const
Expand Down Expand Up @@ -344,7 +347,9 @@ void GPConverter::convert(const std::vector<std::unique_ptr<GPMasterBar> >& mast

addTempoMap();
addInstrumentChanges();
StretchedBend::prepareBends(m_stretchedBends);
if (engravingConfiguration()->experimentalGuitarBendImport()) {
m_guitarBendImporter->applyBendsToChords();
}

addFermatas();
addContinuousSlideHammerOn();
Expand Down Expand Up @@ -2071,16 +2076,8 @@ void GPConverter::addBend(const GPNote* gpnote, Note* note)
return;
}

if (engravingConfiguration()->guitarProImportExperimental()) {
Chord* chord = toChord(note->parent());
StretchedBend* stretchedBend = Factory::createStretchedBend(chord);
stretchedBend->setPitchValues(pitchValues);
stretchedBend->setTrack(note->track());
stretchedBend->setNote(note);
note->setStretchedBend(stretchedBend);

chord->add(stretchedBend);
m_stretchedBends.push_back(stretchedBend);
if (engravingConfiguration()->experimentalGuitarBendImport()) {
m_guitarBendImporter->collectBend(note, pitchValues);
} else {
Bend* bend = Factory::createBend(note);
bend->setPoints(pitchValues);
Expand Down
4 changes: 2 additions & 2 deletions src/importexport/guitarpro/internal/gtp/gpconverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "gpdrumsetresolver.h"
#include "gpmastertracks.h"
#include "../continiouselementsbuilder.h"
#include "../guitarbendimport/guitarbendimporter.h"
#include "types/fraction.h"

#include "iengravingconfiguration.h"
Expand Down Expand Up @@ -192,8 +193,6 @@ class GPConverter : public muse::Injectable
// Index is the number of sharps. Using sharp keysigs for signatures with double flats
std::vector<int> m_sharpsToFlatKeysConverter{ 0, 1, 2, 3, 4, -7, -6, -5, -4, -3, -2, -1 };

std::vector<mu::engraving::StretchedBend*> m_stretchedBends;

static constexpr mu::engraving::voice_idx_t VOICES = 4;

bool m_showCapo = true; // TODO-gp : settings
Expand All @@ -205,6 +204,7 @@ class GPConverter : public muse::Injectable

std::unique_ptr<GPDrumSetResolver> _drumResolver;
std::unique_ptr<ContiniousElementsBuilder> m_continiousElementsBuilder;
std::unique_ptr<GuitarBendImporter> m_guitarBendImporter;
};
} // namespace mu::iex::guitarpro
#endif // MU_IMPORTEXPORT_GPCONVERTER_H
Loading

0 comments on commit 4648888

Please sign in to comment.