Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 42 additions & 107 deletions src/engraving/dom/ambitus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,14 @@ void Ambitus::initFrom(Ambitus* a)

void Ambitus::setTrack(track_idx_t t)
{
Segment* segm = segment();
Staff* stf = score()->staff(track2staff(t));

EngravingItem::setTrack(t);

// if not initialized and there is a segment and a staff,
// initialize pitches and tpc's to first and last staff line
// (for use in palettes)
if (m_topPitch == INVALID_PITCH || m_topTpc == Tpc::TPC_INVALID
|| m_bottomPitch == INVALID_PITCH || m_bottomTpc == Tpc::TPC_INVALID) {
if (segm && stf) {
if (!pitchIsValid(m_topPitch) || !tpcIsValid(m_topTpc)
|| !pitchIsValid(m_bottomPitch) || !tpcIsValid(m_bottomTpc)) {
if (segment() && staff()) {
Ambitus::Ranges ranges = estimateRanges();
m_topTpc = ranges.topTpc;
m_bottomTpc = ranges.bottomTpc;
Expand All @@ -145,9 +143,6 @@ void Ambitus::setTrack(track_idx_t t)
m_topAccidental->setTrack(t);
m_bottomAccidental->setTrack(t);
}
// else {
// _topPitch = _bottomPitch = INVALID_PITCH;
// _topTpc = _bottomTpc = Tpc::TPC_INVALID;
}
}

Expand All @@ -164,19 +159,11 @@ void Ambitus::setTopPitch(int val, bool applyLogic)
return;
}

int deltaPitch = val - topPitch();
// if deltaPitch is not an integer number of octaves, adjust tpc
// if pitch difference is not an integer number of octaves, adjust tpc
// (to avoid 'wild' tpc changes with octave changes)
if (deltaPitch % PITCH_DELTA_OCTAVE != 0) {
int newTpc = topTpc() + deltaPitch * TPC_DELTA_SEMITONE;
// reduce newTpc into acceptable range via enharmonic
while (newTpc < Tpc::TPC_MIN) {
newTpc += TPC_DELTA_ENHARMONIC;
}
while (newTpc > Tpc::TPC_MAX) {
newTpc -= TPC_DELTA_ENHARMONIC;
}
m_topTpc = newTpc;
if ((val - topPitch()) % PITCH_DELTA_OCTAVE != 0) {
Key key = (staff() && segment()) ? staff()->key(segment()->tick()) : Key::C;
m_topTpc = pitch2tpc(val, key, Prefer::NEAREST);
}
m_topPitch = val;
normalize();
Expand All @@ -189,19 +176,11 @@ void Ambitus::setBottomPitch(int val, bool applyLogic)
return;
}

int deltaPitch = val - bottomPitch();
// if deltaPitch is not an integer number of octaves, adjust tpc
// if pitch difference is not an integer number of octaves, adjust tpc
// (to avoid 'wild' tpc changes with octave changes)
if (deltaPitch % PITCH_DELTA_OCTAVE != 0) {
int newTpc = bottomTpc() + deltaPitch * TPC_DELTA_SEMITONE;
// reduce newTpc into acceptable range via enharmonic
while (newTpc < Tpc::TPC_MIN) {
newTpc += TPC_DELTA_ENHARMONIC;
}
while (newTpc > Tpc::TPC_MAX) {
newTpc -= TPC_DELTA_ENHARMONIC;
}
m_bottomTpc = newTpc;
if ((val - bottomPitch()) % PITCH_DELTA_OCTAVE != 0) {
Key key = (staff() && segment()) ? staff()->key(segment()->tick()) : Key::C;
m_bottomTpc = pitch2tpc(val, key, Prefer::NEAREST);
}
m_bottomPitch = val;
normalize();
Expand All @@ -216,37 +195,29 @@ void Ambitus::setBottomPitch(int val, bool applyLogic)

void Ambitus::setTopTpc(int val, bool applyLogic)
{
m_topTpc = val;

if (!applyLogic) {
m_topTpc = val;
return;
}

int octave = topPitch() / PITCH_DELTA_OCTAVE;
int deltaTpc = val - topTpc();
// get new pitch according to tpc change
int newPitch = topPitch() + deltaTpc * TPC_DELTA_SEMITONE;
// reduce pitch to the same octave as original pitch
newPitch = (octave * PITCH_DELTA_OCTAVE) + (newPitch % PITCH_DELTA_OCTAVE);
m_topPitch = newPitch;
m_topTpc = val;
int newOctavedPitch = (tpc2pitch(val) + PITCH_DELTA_OCTAVE) % PITCH_DELTA_OCTAVE;
m_topPitch = (octave * PITCH_DELTA_OCTAVE) + newOctavedPitch;
normalize();
}

void Ambitus::setBottomTpc(int val, bool applyLogic)
{
m_bottomTpc = val;

if (!applyLogic) {
m_bottomTpc = val;
return;
}

int octave = bottomPitch() / PITCH_DELTA_OCTAVE;
int deltaTpc = val - bottomTpc();
// get new pitch according to tpc change
int newPitch = bottomPitch() + deltaTpc * TPC_DELTA_SEMITONE;
// reduce pitch to the same octave as original pitch
newPitch = (octave * PITCH_DELTA_OCTAVE) + (newPitch % PITCH_DELTA_OCTAVE);
m_bottomPitch = newPitch;
m_bottomTpc = val;
int newOctavedPitch = (tpc2pitch(val) + PITCH_DELTA_OCTAVE) % PITCH_DELTA_OCTAVE;
m_bottomPitch = (octave * PITCH_DELTA_OCTAVE) + newOctavedPitch;
normalize();
}

Expand Down Expand Up @@ -296,9 +267,6 @@ SymId Ambitus::noteHead() const

double Ambitus::headWidth() const
{
// int head = noteHead();
// double val = symbols[score()->symIdx()][head].width(magS());
// return val;
return symWidth(noteHead());
}

Expand All @@ -308,12 +276,12 @@ double Ambitus::headWidth() const

PointF Ambitus::pagePos() const
{
if (explicitParent() == 0) {
if (!explicitParent()) {
return pos();
}
System* system = segment()->measure()->system();

double yp = y();
if (system) {
if (System* system = segment()->measure()->system()) {
yp += system->staff(staffIdx())->y() + system->y();
}
return PointF(pageX(), yp);
Expand Down Expand Up @@ -343,70 +311,37 @@ Ambitus::Ranges Ambitus::estimateRanges() const
{
Ambitus::Ranges result;

if (!segment()) {
return result;
}
Chord* chord;
track_idx_t firstTrack = track();
track_idx_t lastTrack = firstTrack + VOICES - 1;
int pitchTop = -1000;
int pitchBottom = 1000;
int tpcTop = 0; // Initialized to prevent warning
int tpcBottom = 0; // Initialized to prevent warning
track_idx_t trk;
Measure* meas = segment()->measure();
Segment* segm = meas->findSegment(SegmentType::ChordRest, segment()->tick());
bool stop = meas->sectionBreak();
while (segm) {
// moved to another measure?
if (segm->measure() != meas) {
// if section break has been found, stop here
if (stop) {
break;
}
// update meas and stop condition
meas = segm->measure();
stop = meas->sectionBreak();
}
// scan all relevant tracks of this segment for chords
for (trk = firstTrack; trk <= lastTrack; trk++) {
EngravingItem* e = segm->element(trk);
Segment* s = segment() ? segment()->measure()->findSegment(SegmentType::ChordRest, segment()->tick()) : nullptr;
for (; s && !s->measure()->sectionBreak(); s = s->nextCR()) {
for (track_idx_t t = track(); t < track() + VOICES; t++) {
EngravingItem* e = s->element(t);
if (!e || !e->isChord()) {
continue;
}
chord = toChord(e);
// update pitch range (with associated tpc's)
Chord* chord = toChord(e);
for (Note* n : chord->notes()) {
if (!n->play()) { // skip notes which are not to be played
if (!n->play()) {
continue;
}
int pitch = n->epitch();
if (pitch > pitchTop) {
pitchTop = pitch;
tpcTop = n->tpc();
int pitch = n->epitch() + n->ottaveCapoFret(); // written pitch, accounting for octave offset
if (pitch > result.topPitch) {
result.topPitch = pitch;
result.topTpc = n->tpc();
}
if (pitch < pitchBottom) {
pitchBottom = pitch;
tpcBottom = n->tpc();
if (pitch < result.bottomPitch) {
result.bottomPitch = pitch;
result.bottomTpc = n->tpc();
}
}
}
segm = segm->nextCR();
}

if (pitchTop > -1000) { // if something has been found, update this
result.topPitch = pitchTop;
result.bottomPitch = pitchBottom;
result.topTpc = tpcTop;
result.bottomTpc = tpcBottom;
}

return result;
}

void Ambitus::remove(EngravingItem* e)
{
if (e->type() == ElementType::ACCIDENTAL) {
if (e->isAccidental()) {
//! NOTE Do nothing (removing _topAccid or _bottomAccid)
return;
}
Expand Down Expand Up @@ -483,10 +418,10 @@ bool Ambitus::setProperty(Pid propertyId, const PropertyValue& v)
setBottomPitch(v.toInt());
break;
case Pid::FBPARENTHESIS3: // recycled property = octave of _topPitch
setTopPitch(topPitch() % 12 + (v.toInt() + 1) * 12);
setTopPitch(topPitch() % PITCH_DELTA_OCTAVE + (v.toInt() + 1) * PITCH_DELTA_OCTAVE);
break;
case Pid::FBPARENTHESIS4: // recycled property = octave of _bottomPitch
setBottomPitch(bottomPitch() % 12 + (v.toInt() + 1) * 12);
setBottomPitch(bottomPitch() % PITCH_DELTA_OCTAVE + (v.toInt() + 1) * PITCH_DELTA_OCTAVE);
break;
default:
return EngravingItem::setProperty(propertyId, v);
Expand Down Expand Up @@ -521,9 +456,9 @@ PropertyValue Ambitus::propertyDefault(Pid id) const
case Pid::FBPARENTHESIS2:
return estimateRanges().bottomPitch;
case Pid::FBPARENTHESIS3:
return int(estimateRanges().topPitch / 12) - 1;
return int(estimateRanges().topPitch / PITCH_DELTA_OCTAVE) - 1;
case Pid::FBPARENTHESIS4:
return int(estimateRanges().bottomPitch / 12) - 1;
return int(estimateRanges().bottomPitch / PITCH_DELTA_OCTAVE) - 1;
default:
return EngravingItem::propertyDefault(id);
}
Expand Down Expand Up @@ -554,7 +489,7 @@ EngravingItem* Ambitus::prevSegmentElement()

String Ambitus::accessibleInfo() const
{
if (m_topTpc == Tpc::TPC_INVALID || m_bottomTpc == Tpc::TPC_INVALID) {
if (!tpcIsValid(m_topTpc) || !tpcIsValid(m_bottomTpc)) {
return EngravingItem::accessibleInfo();
}
return EngravingItem::accessibleInfo() + u"; "
Expand Down
6 changes: 3 additions & 3 deletions src/engraving/dom/ambitus.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ class Ambitus final : public EngravingItem
DirectionH direction() const { return m_direction; }
bool hasLine() const { return m_hasLine; }
Spatium lineWidth() const { return m_lineWidth; }
int topOctave() const { return (m_topPitch / 12) - 1; }
int bottomOctave() const { return (m_bottomPitch / 12) - 1; }
int topOctave() const { return (m_topPitch / PITCH_DELTA_OCTAVE) - 1; }
int bottomOctave() const { return (m_bottomPitch / PITCH_DELTA_OCTAVE) - 1; }
int topPitch() const { return m_topPitch; }
int bottomPitch() const { return m_bottomPitch; }
int topTpc() const { return m_topTpc; }
Expand Down Expand Up @@ -131,7 +131,7 @@ class Ambitus final : public EngravingItem
int topTpc = Tpc::TPC_INVALID;
int bottomTpc = Tpc::TPC_INVALID;
int topPitch = INVALID_PITCH;
int bottomPitch = INVALID_PITCH;
int bottomPitch = MAX_PITCH + 1;
};

Ranges estimateRanges() const; // scan staff up to next section break and update range pitches
Expand Down
32 changes: 16 additions & 16 deletions src/engraving/dom/instrtemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ void InstrumentGroup::clear()

InstrumentTemplate::InstrumentTemplate()
{
staffCount = 1;
minPitchA = 0;
maxPitchA = 127;
minPitchP = 0;
maxPitchP = 127;
staffCount = 1;
minPitchA = MIN_PITCH;
maxPitchA = MAX_PITCH;
minPitchP = MIN_PITCH;
maxPitchP = MAX_PITCH;
staffGroup = StaffGroup::STANDARD;
staffTypePreset = 0;
useDrumset = false;
Expand Down Expand Up @@ -363,11 +363,11 @@ void InstrumentTemplate::write(XmlWriter& xml) const
}
}
}
if (minPitchA != 0 || maxPitchA != 127) {
xml.tag("aPitchRange", String(u"%1-%2").arg(int(minPitchA)).arg(int(maxPitchA)));
if (minPitchA != MIN_PITCH || maxPitchA != MAX_PITCH) {
xml.tag("aPitchRange", String(u"%1-%2").arg(minPitchA).arg(maxPitchA));
}
if (minPitchP != 0 || maxPitchP != 127) {
xml.tag("pPitchRange", String(u"%1-%2").arg(int(minPitchP)).arg(int(maxPitchP)));
if (minPitchP != MIN_PITCH || maxPitchP != MAX_PITCH) {
xml.tag("pPitchRange", String(u"%1-%2").arg(minPitchP).arg(maxPitchP));
}
if (transpose.diatonic) {
xml.tag("transposeDiatonic", transpose.diatonic);
Expand Down Expand Up @@ -491,9 +491,9 @@ void InstrumentTemplate::read(XmlReader& e)
barlineSpan[idx + i] = true;
}
} else if (tag == "aPitchRange") {
setPitchRange(e.readText(), &minPitchA, &maxPitchA);
setPitchRange(e.readText(), minPitchA, maxPitchA);
} else if (tag == "pPitchRange") {
setPitchRange(e.readText(), &minPitchP, &maxPitchP);
setPitchRange(e.readText(), minPitchP, maxPitchP);
} else if (tag == "transposition") { // obsolete
int i = e.readInt();
transpose.chromatic = i;
Expand Down Expand Up @@ -627,16 +627,16 @@ void InstrumentTemplate::read(XmlReader& e)
// setPitchRange
//---------------------------------------------------------

void InstrumentTemplate::setPitchRange(const String& s, char* a, char* b) const
void InstrumentTemplate::setPitchRange(const String& s, int& a, int& b) const
{
StringList sl = s.split(u'-');
if (sl.size() != 2) {
*a = 0;
*b = 127;
a = MIN_PITCH;
b = MAX_PITCH;
return;
}
*a = sl.at(0).toInt();
*b = sl.at(1).toInt();
a = sl.at(0).toInt();
b = sl.at(1).toInt();
}

//---------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions src/engraving/dom/instrtemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ class InstrumentTemplate

Trait trait;

char minPitchA = 0; // pitch range playable by an amateur
char maxPitchA = 0;
char minPitchP = 0; // pitch range playable by professional
char maxPitchP = 0;
int minPitchA = 0; // pitch range playable by an amateur
int maxPitchA = 0;
int minPitchP = 0; // pitch range playable by professional
int maxPitchP = 0;

Interval transpose; // for transposing instruments

Expand Down Expand Up @@ -139,7 +139,7 @@ class InstrumentTemplate

private:
void init(const InstrumentTemplate&);
void setPitchRange(const String& s, char* a, char* b) const;
void setPitchRange(const String& s, int& a, int& b) const;
void linkGenre(const String&);
};

Expand Down
8 changes: 4 additions & 4 deletions src/engraving/dom/instrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ Instrument::Instrument(String id)
a->setName(String::fromUtf8(InstrChannel::DEFAULT_NAME));
m_channel.push_back(a);

m_minPitchA = 0;
m_maxPitchA = 127;
m_minPitchP = 0;
m_maxPitchP = 127;
m_minPitchA = MIN_PITCH;
m_maxPitchA = MAX_PITCH;
m_minPitchP = MIN_PITCH;
m_maxPitchP = MAX_PITCH;
m_useDrumset = false;
m_drumset = 0;
m_singleNoteDynamics = true;
Expand Down
Loading
Loading