Skip to content

Commit

Permalink
bugfixing fret diagram+harmony
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Dec 10, 2012
1 parent 23d29f6 commit 8883029
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 17 deletions.
2 changes: 2 additions & 0 deletions libmscore/element.cpp
Expand Up @@ -507,6 +507,7 @@ QPointF Element::pagePos() const
return p;

if (_flags & ELEMENT_ON_STAFF) {
Q_ASSERT(parent()->type() == SEGMENT);
System* system = static_cast<Segment*>(parent())->measure()->system();
if (system) {
int si = staffIdx();
Expand All @@ -533,6 +534,7 @@ QPointF Element::canvasPos() const
if (parent() == 0)
return p;
if (_flags & ELEMENT_ON_STAFF) {
Q_ASSERT(parent()->type() == SEGMENT);
System* system = static_cast<Segment*>(parent())->measure()->system();
if (system) {
int si = staffIdx();
Expand Down
28 changes: 21 additions & 7 deletions libmscore/fret.cpp
Expand Up @@ -25,14 +25,17 @@
static const int DEFAULT_STRINGS = 6;
static const int DEFAULT_FRETS = 5;

// parent() is Segment or Box
//

//---------------------------------------------------------
// FretDiagram
//---------------------------------------------------------

FretDiagram::FretDiagram(Score* score)
: Element(score)
{
setFlag(ELEMENT_MOVABLE, true);
setFlags(ELEMENT_MOVABLE | ELEMENT_ON_STAFF | ELEMENT_SELECTABLE);
_strings = DEFAULT_STRINGS;
_frets = DEFAULT_FRETS;
_maxFrets = 24;
Expand Down Expand Up @@ -88,6 +91,7 @@ FretDiagram::~FretDiagram()
delete _fingering;
}

#if 1
//---------------------------------------------------------
// pagePos
//---------------------------------------------------------
Expand All @@ -107,6 +111,7 @@ QPointF FretDiagram::pagePos() const
else
return Element::pagePos();
}
#endif

//---------------------------------------------------------
// dragAnchor
Expand Down Expand Up @@ -280,14 +285,21 @@ void FretDiagram::layout()
h -= y;
}
setbbox(QRectF(x, y, w, h));

setPos(-_spatium, -h - _spatium);
adjustReadPos();

MStaff* mstaff = segment()->measure()->mstaff(staffIdx());
mstaff->distanceUp = qMax(mstaff->distanceUp, h + _spatium * 4);

if (_harmony)
_harmony->layout();

if (parent() == 0)
return;
Measure* m = segment()->measure();
int idx = staffIdx();
MStaff* mstaff = m->mstaff(idx);
System* system = m->system();
qreal yp = pos().y() + system->staff(idx)->y() + system->y();
mstaff->distanceUp = qMax(mstaff->distanceUp, h + _spatium * 2 - yp);
}

//---------------------------------------------------------
Expand Down Expand Up @@ -422,6 +434,7 @@ void FretDiagram::add(Element* e)
e->setParent(this);
if (e->type() == HARMONY) {
_harmony = static_cast<Harmony*>(e);
_harmony->setTrack(track());
}
else
qWarning("FretDiagram: cannot add <%s>\n", e->name());
Expand Down Expand Up @@ -457,14 +470,15 @@ Element* FretDiagram::drop(const DropData& data)
Element* e = data.element;
if (e->type() == HARMONY) {
// TODO: make undoable
_harmony = static_cast<Harmony*>(e);
score()->setUpdateAll(true);
Harmony* h = static_cast<Harmony*>(e);
h->setParent(this);
score()->undoAddElement(h);
}
else {
qWarning("FretDiagram: cannot drop <%s>\n", e->name());
delete e;
e = 0;
}
qWarning("FretDiagram: cannot drop <%s>\n", e->name());
return e;
}

Expand Down
3 changes: 2 additions & 1 deletion libmscore/fret.h
Expand Up @@ -50,7 +50,6 @@ class FretDiagram : public Element {
virtual void draw(QPainter*) const;
virtual FretDiagram* clone() const { return new FretDiagram(*this); }
Segment* segment() const { return (Segment*)parent(); }
// Measure* measure() const { return (Measure*)parent()->parent(); }

virtual ElementType type() const { return FRET_DIAGRAM; }
virtual void layout();
Expand All @@ -77,6 +76,8 @@ class FretDiagram : public Element {

char* dots() { return _dots; }
char* marker() { return _marker; }
Harmony* harmony() const { return _harmony; }

char* fingering() { return _fingering; }
void init(Tablature*, Chord*);

Expand Down
50 changes: 45 additions & 5 deletions libmscore/harmony.cpp
Expand Up @@ -19,6 +19,7 @@
#include "segment.h"
#include "chordlist.h"
#include "mscore.h"
#include "fret.h"

//---------------------------------------------------------
// harmonyName
Expand Down Expand Up @@ -536,23 +537,36 @@ void Harmony::layout()
return;
}
textStyle().layout(this);
if (parent()) {
Measure* m = measure();
if (!parent()) {
setPos(QPointF(0.0, 0.0));
return;
}
if (parent()->type() == SEGMENT) {
Measure* m = static_cast<Measure*>(parent()->parent());
qreal yy = track() < 0 ? 0.0 : m->system()->staff(track() / VOICES)->y();
setPos(ipos() + QPointF(0.0, yy));
}
else
setPos(QPointF(0.0, 0.0));

QRectF bb;
foreach(const TextSegment* ts, textList)
bb |= ts->boundingRect().translated(ts->x, ts->y);
setbbox(bb);
if (!readPos().isNull()) {
// version 114 is measure based
// rebase to segment
if (score()->mscVersion() == 114)
setReadPos(readPos() - segment()->pos());
if (score()->mscVersion() == 114) {
setReadPos(readPos() - parent()->pos());
}
setUserOff(readPos() - ipos());
setReadPos(QPointF());
}
if (parent()->type() == FRET_DIAGRAM) {
MStaff* mstaff = measure()->mstaff(staffIdx());
qreal dist = -(bbox().top());
mstaff->distanceUp = qMax(mstaff->distanceUp, dist + spatium());
}
}

//---------------------------------------------------------
Expand Down Expand Up @@ -772,7 +786,11 @@ QLineF Harmony::dragAnchor() const
qreal xp = 0.0;
for (Element* e = parent(); e; e = e->parent())
xp += e->x();
qreal yp = measure()->system()->staffY(staffIdx());
qreal yp;
if (parent()->type() == SEGMENT)
yp = static_cast<Segment*>(parent())->measure()->system()->staffY(staffIdx());
else
yp = parent()->canvasPos().y();
QPointF p(xp, yp);
return QLineF(p, canvasPos());
}
Expand Down Expand Up @@ -849,3 +867,25 @@ const QList<HDegree>& Harmony::degreeList() const
return _degreeList;
}

//---------------------------------------------------------
// segment
//---------------------------------------------------------

Segment* Harmony::segment() const
{
if (parent()->type() == FRET_DIAGRAM)
return static_cast<FretDiagram*>(parent())->segment();
if (parent()->type() == SEGMENT)
return static_cast<Segment*>(parent());
return 0;
}

//---------------------------------------------------------
// measure
//---------------------------------------------------------

Measure* Harmony::measure() const
{
return segment()->measure();
}

4 changes: 2 additions & 2 deletions libmscore/harmony.h
Expand Up @@ -85,8 +85,8 @@ class Harmony : public Text {
~Harmony();
virtual Harmony* clone() const { return new Harmony(*this); }
virtual ElementType type() const { return HARMONY; }
Segment* segment() const { return (Segment*)parent(); }
Measure* measure() const { return (Measure*)(parent()->parent()); }
Segment* segment() const;
Measure* measure() const;

void setId(int d) { _id = d; }
int id() const { return _id; }
Expand Down
2 changes: 1 addition & 1 deletion libmscore/system.cpp
Expand Up @@ -944,7 +944,7 @@ void System::scanElements(void* data, void (*func)(void*, Element*), bool all)
qreal System::staffY(int staffIdx) const
{
if (_staves.size() <= staffIdx) {
qDebug("staffY: staves %d <= staff %d, vbox %d",
qDebug("staffY: staves %d <= staffIdx %d, vbox %d",
_staves.size(), staffIdx, _vbox);
return pagePos().y();
}
Expand Down
7 changes: 6 additions & 1 deletion libmscore/transpose.cpp
Expand Up @@ -24,6 +24,7 @@
#include "stafftype.h"
#include "chord.h"
#include "measure.h"
#include "fret.h"

//---------------------------------------------------------
// keydiff2Interval
Expand Down Expand Up @@ -315,7 +316,11 @@ void Score::transpose(int mode, TransposeDirection direction, int transposeKey,
Harmony* h = static_cast<Harmony*>(e);
int rootTpc, baseTpc;
if (mode == TRANSPOSE_DIATONICALLY) {
int tick = h->segment()->tick();
int tick = 0;
if (h->parent()->type() == Element::SEGMENT)
tick = static_cast<Segment*>(h->parent())->tick();
else if (h->parent()->type() == Element::FRET_DIAGRAM)
tick = static_cast<FretDiagram*>(h->parent())->segment()->tick();
int key = !h->staff() ? KEY_C : h->staff()->keymap()->key(tick).accidentalType();
rootTpc = transposeTpcDiatonicByKey(h->rootTpc(),
transposeInterval, key, trKeys, useDoubleSharpsFlats);
Expand Down
8 changes: 8 additions & 0 deletions mscore/debugger.cpp
Expand Up @@ -59,6 +59,8 @@
#include "libmscore/notedot.h"
#include "libmscore/spacer.h"
#include "libmscore/box.h"
#include "libmscore/fret.h"
#include "libmscore/harmony.h"

extern bool useFactorySettings;

Expand Down Expand Up @@ -409,6 +411,12 @@ void Debugger::updateList(Score* s)
foreach(Element* s, segment->annotations()) {
if (s->type() == Element::SYMBOL || s->type() == Element::IMAGE)
addBSymbol(segItem, static_cast<BSymbol*>(s));
else if (s->type() == Element::FRET_DIAGRAM) {
ElementItem* fdi = new ElementItem(segItem, s);
FretDiagram* fd = static_cast<FretDiagram*>(s);
if (fd->harmony())
new ElementItem(fdi, fd->harmony());
}
else
new ElementItem(segItem, s);
}
Expand Down

0 comments on commit 8883029

Please sign in to comment.