Skip to content

Commit

Permalink
* Note: Add method to get TPitch from note
Browse files Browse the repository at this point in the history
  • Loading branch information
earboxer committed Dec 6, 2019
1 parent 84c72d6 commit 011a407
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 16 deletions.
4 changes: 4 additions & 0 deletions include/vrv/note.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
#include "durationinterface.h"
#include "layerelement.h"
#include "pitchinterface.h"
#include "transpose.h"

namespace vrv {

class Accid;
class Chord;
class Slur;
class Tie;
class TPitch;
class Verse;
class Note;
typedef std::vector<Note *> ChordCluster;
Expand Down Expand Up @@ -187,6 +189,8 @@ class Note : public LayerElement,
*/
int GetChromaticAlteration();

TPitch GetTPitch();

//----------//
// Functors //
//----------//
Expand Down
34 changes: 34 additions & 0 deletions include/vrv/transpose.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Name: transpose.h
// Author: Zach DeCook
// Created: December 5 2019
//

#ifndef __VRV_TRANSPOSE_H__
#define __VRV_TRANSPOSE_H__

#include <iostream>

namespace vrv {

class TPitch;

class TPitch {
public:
int pname; // diatonic pitch class name: C = 0, D = 1, ... B = 6.
int accid; // chromatic alteration: 0 = natural, 1 = sharp, -2 = flat, +2 = double sharp
int oct; // octave number: 4 = middle-C octave

TPitch(){};
TPitch(int aPname, int anAccid, int anOct);
TPitch(const TPitch &pitch);
TPitch &operator=(const TPitch &pitch);
bool isValid(int maxAccid);
void setPitch(int aPname, int anAccid, int anOct);
};

std::ostream &operator<<(std::ostream &out, const TPitch &pitch);

} // namespace vrv

#endif
7 changes: 7 additions & 0 deletions src/note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "staff.h"
#include "syl.h"
#include "tie.h"
#include "transpose.h"
#include "verse.h"
#include "vrv.h"

Expand Down Expand Up @@ -452,6 +453,12 @@ int Note::GetChromaticAlteration()
return 0;
}

TPitch Note::GetTPitch()
{
int pname = this->GetPname() - PITCHNAME_c;
return TPitch(pname, this->GetChromaticAlteration(), this->GetOct());
}

//----------------------------------------------------------------------------
// Functors methods
//----------------------------------------------------------------------------
Expand Down
21 changes: 5 additions & 16 deletions src/transpose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
#define dpc_A 5
#define dpc_B 6

#include "transpose.h"

#include <iostream>
#include <string>
#include <vector>
Expand All @@ -55,22 +57,7 @@
// note/accid in MEI data, and other complications that need to be resolved into
// storing the correct pitch information in TPitch.
//

class TPitch {
public:
int pname; // diatonic pitch class name: C = 0, D = 1, ... B = 6.
int accid; // chromatic alteration: 0 = natural, 1 = sharp, -2 = flat, +2 = double sharp
int oct; // octave number: 4 = middle-C octave

TPitch(){};
TPitch(int aPname, int anAccid, int anOct);
TPitch(const TPitch &pitch);
TPitch &operator=(const TPitch &pitch);
void setPitch(int aPname, int anAccid, int anOct);
bool isValid(int maxAccid);
};

std::ostream &operator<<(std::ostream &out, const TPitch &pitch);
namespace vrv {

//////////////////////////////
//
Expand Down Expand Up @@ -1030,3 +1017,5 @@ int main(void)
Interval between C4 and F##4 is AA4
Interval between C4 and Gbb3 is -AA4
*/

} // namespace vrv

0 comments on commit 011a407

Please sign in to comment.