Skip to content

Commit

Permalink
Get Pitch position at date (in progress)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfober committed Dec 6, 2023
1 parent 47503f8 commit 041f750
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
6 changes: 1 addition & 5 deletions src/engine/lib/GUIDOEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,12 +637,8 @@ GUIDOAPI GuidoErrCode GuidoGetPitchPos( CGRHandler inHandleGR, int staffnum, int
return guidoErrInvalidHandle;

TYPE_TIMEPOSITION tp (date.num, date.denom);
GRStaff* staff = inHandleGR->grmusic->getStaff (staffnum, tp);
if (!staff)
return guidoErrBadParameter;

GRPitchYVisitor v;
NVPoint p = v.getPitchPos (staff, pitch, tp);
NVPoint p = v.getPitchPos (inHandleGR->grmusic, staffnum, pitch, tp);
if (!p.x)
return guidoErrBadParameter;
x = p.x;
Expand Down
40 changes: 26 additions & 14 deletions src/engine/operations/GRPitchYVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "GuidoDefs.h"
#include "GRClef.h"
#include "GREmpty.h"
#include "GRMusic.h"
#include "GROctava.h"
#include "GREvent.h"
#include "GRSingleNote.h"
Expand All @@ -23,8 +24,10 @@
using namespace std;

//-------------------------------------------------------------------------------
NVPoint GRPitchYVisitor::getPitchPos (GRStaff* staff, int midipitch, TYPE_TIMEPOSITION date)
NVPoint GRPitchYVisitor::getPitchPos (GRMusic* music, int staffNum, int midipitch, TYPE_TIMEPOSITION date)
{
fTargetStaff = staffNum;
fCurrentStaff = 0;
fBasePitch = NOTE_G;
fBaseLine = 3;
fBaseOct = 1;
Expand All @@ -33,27 +36,36 @@ NVPoint GRPitchYVisitor::getPitchPos (GRStaff* staff, int midipitch, TYPE_TIMEPO
fLastDate = -1;
fLastX = -1;
fDone = false;
staff->accept (*this);
fStaff = nullptr;
music->accept (*this);
NVPoint p;
if (fDone) {
if (fDone && fStaff) {
// convert midi pitch in pitch class and octava
int oct = (midipitch / 12) - 4;
int pitch = midipitch % 12;
pitch = ((pitch < 5) ? (pitch / 2) : (pitch+1) / 2) + 2;
cerr << "GRPitchYVisitor::getPitchPos " << pitch << " " << oct << " date: " << date << endl;
float y = staff->getNotePosition ( pitch, oct, fBasePitch, fBaseLine, fBaseOct);
//cerr << "GRPitchYVisitor::getPitchPos " << pitch << " " << oct << " date: " << date << endl;
float y = fStaff->getNotePosition ( pitch, oct, fBasePitch, fBaseLine, fBaseOct);
p.x = fLastX;
p.y = y;
}
cerr << " resultat : " << p << endl;
return p;
}

//-------------------------------------------------------------------------------
void GRPitchYVisitor::visitStart (GRSingleNote* o)
void GRPitchYVisitor::visitStart (GRStaff* o)
{
if (fDone) return;
cerr << "GRPitchYVisitor::visitStart GRSingleNote " << o << endl;
fCurrentStaff = o->getStaffNumber();
//cerr << "GRPitchYVisitor::visitStart GRStaff " << fCurrentStaff << endl;
fStaff = o;
}

//-------------------------------------------------------------------------------
void GRPitchYVisitor::visitStart (GRSingleNote* o)
{
if (fDone || (fCurrentStaff != fTargetStaff)) return;
//cerr << "GRPitchYVisitor::visitStart GRSingleNote " << o << endl;
TYPE_TIMEPOSITION date = o->getRelativeTimePosition();
if (date > fTargetDate) fDone = true;
else fLastX = o->getPosition().x;
Expand All @@ -62,8 +74,8 @@ cerr << "GRPitchYVisitor::visitStart GRSingleNote " << o << endl;
//-------------------------------------------------------------------------------
void GRPitchYVisitor::visitStart (GREmpty* o)
{
if (fDone) return;
cerr << "GRPitchYVisitor::visitStart GREmpty " << o << endl;
if (fDone || (fCurrentStaff != fTargetStaff)) return;
//cerr << "GRPitchYVisitor::visitStart GREmpty " << o << endl;
TYPE_TIMEPOSITION date = o->getRelativeTimePosition();
if (date > fTargetDate) fDone = true;
else fLastX = o->getPosition().x;
Expand All @@ -72,22 +84,22 @@ cerr << "GRPitchYVisitor::visitStart GREmpty " << o << endl;
//-------------------------------------------------------------------------------
void GRPitchYVisitor::visitStart (GRSingleRest* o)
{
if (fDone) return;
cerr << "GRPitchYVisitor::visitStart GRSingleRest " << o << endl;
if (fDone || (fCurrentStaff != fTargetStaff)) return;
//cerr << "GRPitchYVisitor::visitStart GRSingleRest " << o << endl;
TYPE_TIMEPOSITION date = o->getRelativeTimePosition();
if (date > fTargetDate) fDone = true;
else fLastX = o->getPosition().x;
}

void GRPitchYVisitor::visitStart (GRClef* o)
{
if (fDone) return;
if (fDone || (fCurrentStaff != fTargetStaff)) return;
fBasePitch = o->getBasePitch();
fBaseOct = o->getBaseOct();
}

void GRPitchYVisitor::visitStart (GROctava* o)
{
if (fDone) return;
if (fDone || (fCurrentStaff != fTargetStaff)) return;
fOctava = o->getOctava();
}
8 changes: 6 additions & 2 deletions src/engine/operations/GRPitchYVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

class GRPitchYVisitor : public GRVisitor
{
int fTargetStaff;
int fCurrentStaff;
int fBasePitch;
int fBaseLine;
int fBaseOct;
Expand All @@ -25,20 +27,22 @@ class GRPitchYVisitor : public GRVisitor
TYPE_TIMEPOSITION fLastDate = 0;
TYPE_TIMEPOSITION fTargetDate = 0;
bool fDone = false;
const GRStaff * fStaff;

public:
GRPitchYVisitor() {}
virtual ~GRPitchYVisitor() {}

NVPoint getPitchPos (GRStaff* staff, int pitch, TYPE_TIMEPOSITION date);
NVPoint getPitchPos (GRMusic* music, int staffNum, int pitch, TYPE_TIMEPOSITION date);

virtual bool voiceMode () { return true; }
virtual bool voiceMode () { return false; }

virtual void visitStart (GRClef* o);
virtual void visitStart (GROctava* o);
virtual void visitStart (GRSingleNote* o);
virtual void visitStart (GRSingleRest* o);
virtual void visitStart (GREmpty* o);
virtual void visitStart (GRStaff* o);
};

#endif

0 comments on commit 041f750

Please sign in to comment.