Skip to content

Commit

Permalink
Add LDP OctaveShift element
Browse files Browse the repository at this point in the history
  • Loading branch information
cecilios committed Jul 31, 2024
1 parent 5094252 commit baed8ae
Show file tree
Hide file tree
Showing 5 changed files with 337 additions and 2 deletions.
14 changes: 14 additions & 0 deletions include/lomse_ldp_analyser.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ class SlursBuilder : public RelationBuilder<ImoSlurDto, LdpAnalyser>
};


//---------------------------------------------------------------------------------------
// helper class to save octave-shift info items, match them and build the octave-shift lines
class OctaveShiftBuilder : public RelationBuilder<ImoOctaveShiftDto, LdpAnalyser>
{
public:
OctaveShiftBuilder(ostream& reporter, LdpAnalyser* pAnalyser)
: RelationBuilder<ImoOctaveShiftDto, LdpAnalyser>(reporter, pAnalyser, "octaveShift", "octave-shift") {}
virtual ~OctaveShiftBuilder() {}

void add_relation_to_staffobjs(ImoOctaveShiftDto* pEndInfo) override;
};



//---------------------------------------------------------------------------------------
// helper class to save beam info items, match them and build the beams
Expand Down Expand Up @@ -174,6 +187,7 @@ class LdpAnalyser : public Analyser
OldBeamsBuilder* m_pOldBeamsBuilder;
TupletsBuilder* m_pTupletsBuilder;
SlursBuilder* m_pSlursBuilder;
OctaveShiftBuilder* m_pOctaveShifBuilder;
map<string, int> m_lyricIndex;
vector<ImoLyric*> m_lyrics;
vector<int> m_lyricsPlacement;
Expand Down
1 change: 1 addition & 0 deletions include/lomse_ldp_elements.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ enum ELdpElement
k_textbox,
k_line,
k_lyric,
k_octave_shift,
k_tie,
k_tuplet,
//pauses and breath marks
Expand Down
151 changes: 150 additions & 1 deletion src/parser/ldp/lomse_ldp_analyser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3700,6 +3700,7 @@ class NoteRestAnalyser : public ElementAnalyser
ImoTupletDto* m_pTupletInfo;
ImoBeamDto* m_pBeamInfo;
ImoSlurDto* m_pSlurDto;
ImoOctaveShiftDto* m_pOctaveShiftDto;
ImoFermata* m_pFermata;
ImoTimeModificationDto* m_pTimeModifDto;
std::string m_srcOldBeam;
Expand All @@ -3713,6 +3714,7 @@ class NoteRestAnalyser : public ElementAnalyser
, m_pTupletInfo(nullptr)
, m_pBeamInfo(nullptr)
, m_pSlurDto(nullptr)
, m_pOctaveShiftDto(nullptr)
, m_pFermata(nullptr)
, m_pTimeModifDto(nullptr)
, m_srcOldBeam("")
Expand Down Expand Up @@ -3853,6 +3855,9 @@ class NoteRestAnalyser : public ElementAnalyser
//slur
add_slur_info(pNote);

//octave-shift
add_octave_shift_info(pNR);

//chord
if (!fIsRest && fInChord)
{
Expand Down Expand Up @@ -3880,7 +3885,7 @@ class NoteRestAnalyser : public ElementAnalyser

void analyse_note_rest_options(ImoNoteRest* pNR)
{
// { <beam> | <tuplet> | <timeModification> | <voice> }
// { <beam> | <tuplet> | <timeModification> | <voice> | <octaveShift> }

while( more_params_to_analyse() )
{
Expand All @@ -3905,6 +3910,10 @@ class NoteRestAnalyser : public ElementAnalyser
{
set_voice_element(pNR);
}
else if (type == k_octave_shift)
{
m_pOctaveShiftDto = static_cast<ImoOctaveShiftDto*>( proceed(k_octave_shift, nullptr) );
}
else
break;

Expand Down Expand Up @@ -4203,6 +4212,112 @@ class NoteRestAnalyser : public ElementAnalyser
}
}

void add_octave_shift_info(ImoNoteRest* pNR)
{
if (m_pOctaveShiftDto)
{
m_pOctaveShiftDto->set_staffobj(pNR);
m_pAnalyser->add_relation_info(m_pOctaveShiftDto);
}
}
};


//@--------------------------------------------------------------------------------------
//@ <octaveShift> = (octaveShift num <startStop>[<octaveShiftType>][color] )
//@ num = octaveShift number. integer
//@ <startStop> = { start | stop }
//@ <octaveShiftType> = { 8u | 8d | 15u | 15d }
//@
//@ Example:
//@ (octaveShift 18 start 8d)
//@

class octaveShiftAnalyser : public ElementAnalyser
{
protected:
ImoOctaveShiftDto* m_pInfo = nullptr;

public:
octaveShiftAnalyser(LdpAnalyser* pAnalyser, ostream& reporter, LibraryScope& libraryScope,
ImoObj* pAnchor)
: ElementAnalyser(pAnalyser, reporter, libraryScope, pAnchor) {}

void do_analysis() override
{
Document* pDoc = m_pAnalyser->get_document_being_analysed();
m_pInfo = static_cast<ImoOctaveShiftDto*>(
ImFactory::inject(k_imo_octave_shift_dto, pDoc));
m_pInfo->set_id( get_node_id() );
m_pInfo->set_line_number( m_pAnalysedNode->get_line_number() );

// num
if (get_mandatory(k_number))
m_pInfo->set_octave_shift_number( get_integer_value(0) );

// <startStop> (label)
if (!get_mandatory(k_label) || !set_start_stop())
{
error_msg("Missing or invalid value for octaveShift start/stop. Octave-shift ignored.");
delete m_pInfo;
return;
}

// <octaveShiftType> (label)
if (m_pInfo->is_start())
{
if (get_optional(k_label))
{
set_octave_shift_type();

// [<color>]
if (get_optional(k_color))
m_pInfo->set_color( get_color_param() );
}
}
else
{
// int id = m_pAnalyser->get_octave_shift_id_and_close(num);
}

error_if_more_elements();

m_pAnalysedNode->set_imo(m_pInfo);
}

protected:

bool set_start_stop()
{
const std::string& value = m_pParamToAnalyse->get_value();
if (value == "start")
m_pInfo->set_start(true);
else if (value == "stop")
m_pInfo->set_start(false);
else
return false; //error
return true; //ok
}

void set_octave_shift_type()
{
const std::string& value = m_pParamToAnalyse->get_value();
int size = 0; //any value, just to initialize it
if (value == "8u")
size =-7;
else if (value == "8d")
size = 7;
else if (value == "15u")
size = -14;
else if (value == "15d")
size = 14;
else
{
error_msg("Invalid octave-shift size '" + value + "'. Changed to 8u.");
size = -7;
}
m_pInfo->set_shift_steps(size);
}
};

//@--------------------------------------------------------------------------------------
Expand Down Expand Up @@ -6449,6 +6564,7 @@ LdpAnalyser::LdpAnalyser(ostream& reporter, LibraryScope& libraryScope, Document
, m_pOldBeamsBuilder(nullptr)
, m_pTupletsBuilder(nullptr)
, m_pSlursBuilder(nullptr)
, m_pOctaveShifBuilder(nullptr)
, m_pCurScore(nullptr)
, m_pLastScore(nullptr)
, m_pImoDoc(nullptr)
Expand Down Expand Up @@ -6495,6 +6611,7 @@ void LdpAnalyser::delete_relation_builders()
delete m_pOldBeamsBuilder;
delete m_pTupletsBuilder;
delete m_pSlursBuilder;
delete m_pOctaveShifBuilder;
}

//---------------------------------------------------------------------------------------
Expand All @@ -6507,6 +6624,7 @@ ImoObj* LdpAnalyser::analyse_tree_and_get_object(LdpTree* tree)
m_pOldBeamsBuilder = LOMSE_NEW OldBeamsBuilder(m_reporter, this);
m_pTupletsBuilder = LOMSE_NEW TupletsBuilder(m_reporter, this);
m_pSlursBuilder = LOMSE_NEW SlursBuilder(m_reporter, this);
m_pOctaveShifBuilder = LOMSE_NEW OctaveShiftBuilder(m_reporter, this);

m_pTree = tree;
m_curStaff = 0;
Expand Down Expand Up @@ -6723,6 +6841,8 @@ void LdpAnalyser::add_relation_info(ImoObj* pDto)
m_pBeamsBuilder->add_item_info(static_cast<ImoBeamDto*>(pDto));
else if (pDto->is_tuplet_dto())
m_pTupletsBuilder->add_item_info(static_cast<ImoTupletDto*>(pDto));
else if (pDto->is_octave_shift_dto())
m_pOctaveShifBuilder->add_item_info(static_cast<ImoOctaveShiftDto*>(pDto));
}

//---------------------------------------------------------------------------------------
Expand All @@ -6733,6 +6853,7 @@ void LdpAnalyser::clear_pending_relations()
m_pBeamsBuilder->clear_pending_items();
m_pOldBeamsBuilder->clear_pending_old_beams();
m_pTupletsBuilder->clear_pending_items();
m_pOctaveShifBuilder->clear_pending_items();

m_lyrics.clear();
m_lyricIndex.clear();
Expand Down Expand Up @@ -7101,6 +7222,7 @@ ElementAnalyser* LdpAnalyser::new_analyser(ELdpElement type, ImoObj* pAnchor)
case k_name: return LOMSE_NEW InstrNameAnalyser(this, m_reporter, m_libraryScope, pAnchor);
case k_newSystem: return LOMSE_NEW ControlAnalyser(this, m_reporter, m_libraryScope, pAnchor);
case k_note: return LOMSE_NEW NoteRestAnalyser(this, m_reporter, m_libraryScope, pAnchor);
case k_octave_shift: return LOMSE_NEW octaveShiftAnalyser(this, m_reporter, m_libraryScope, pAnchor);
case k_opt: return LOMSE_NEW OptAnalyser(this, m_reporter, m_libraryScope, pAnchor);
case k_orderedlist: return LOMSE_NEW ListAnalyser(this, m_reporter, m_libraryScope, pAnchor);
case k_pageLayout: return LOMSE_NEW PageLayoutAnalyser(this, m_reporter, m_libraryScope, pAnchor);
Expand Down Expand Up @@ -7314,6 +7436,33 @@ void SlursBuilder::add_relation_to_staffobjs(ImoSlurDto* pEndInfo)



//=======================================================================================
// OctaveShiftBuilder implementation
//=======================================================================================
void OctaveShiftBuilder::add_relation_to_staffobjs(ImoOctaveShiftDto* pEndInfo)
{
m_matches.push_back(pEndInfo);
Document* pDoc = m_pAnalyser->get_document_being_analysed();

ImoOctaveShiftDto* pStartInfo = m_matches.front();
ImoOctaveShift* pShift = static_cast<ImoOctaveShift*>(
ImFactory::inject(k_imo_octave_shift, pDoc, pStartInfo->get_id()) );
pShift->set_octave_shift_number( pStartInfo->get_octave_shift_number() );
pShift->set_shift_steps( pStartInfo->get_shift_steps() );
pShift->set_color( pStartInfo->get_color() );

std::list<ImoOctaveShiftDto*>::iterator it;
for (it = m_matches.begin(); it != m_matches.end(); ++it)
{
ImoNoteRest* pNR = (*it)->get_staffobj();
//ImoOctaData* pData = ImFactory::inject_slur_data(pDoc, *it);
//pNote->include_in_relation(pShift, pData);
pNR->include_in_relation(pShift, nullptr);
}
}



//=======================================================================================
// BeamsBuilder implementation
//=======================================================================================
Expand Down
4 changes: 3 additions & 1 deletion src/parser/lomse_ldp_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ LdpFactory::LdpFactory()
m_TypeToName[k_no] = "no";
m_TypeToName[k_normal] = "normal";
m_TypeToName[k_note] = "n"; //note
m_TypeToName[k_opt] = "opt";
m_TypeToName[k_slur] = "slur";
m_TypeToName[k_octave_shift] = "octaveShift";
m_TypeToName[k_orderedlist] = "orderedlist";
m_TypeToName[k_padding] = "padding";
m_TypeToName[k_padding_top] = "padding-top";
Expand Down Expand Up @@ -368,6 +369,7 @@ LdpFactory::LdpFactory()
m_NameToFunctor["newSystem"] = LOMSE_NEW LdpElementFunctor<k_newSystem>;
m_NameToFunctor["no"] = LOMSE_NEW LdpElementFunctor<k_no>;
m_NameToFunctor["normal"] = LOMSE_NEW LdpElementFunctor<k_normal>;
m_NameToFunctor["octaveShift"] = LOMSE_NEW LdpElementFunctor<k_octave_shift>;
m_NameToFunctor["opt"] = LOMSE_NEW LdpElementFunctor<k_opt>;
m_NameToFunctor["orderedlist"] = LOMSE_NEW LdpElementFunctor<k_orderedlist>;
m_NameToFunctor["padding"] = LOMSE_NEW LdpElementFunctor<k_padding>;
Expand Down
Loading

0 comments on commit baed8ae

Please sign in to comment.