本文整理汇总了C++中Voice::bar方法的典型用法代码示例。如果您正苦于以下问题:C++ Voice::bar方法的具体用法?C++ Voice::bar怎么用?C++ Voice::bar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Voice
的用法示例。
在下文中一共展示了Voice::bar方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: renderKeyboardPreview
void NoteEntryAction::renderKeyboardPreview(QPainter& painter, const MusicCursor& cursor)
{
Staff* staff = cursor.staff();
Part* part = staff->part();
Sheet* sheet = part->sheet();
Bar* bar = sheet->bar(cursor.bar());
QPointF p = bar->position() + QPointF(0, staff->top());
Voice* voice = cursor.staff()->part()->voice(cursor.voice());
VoiceBar* vb = voice->bar(bar);
if (cursor.element() >= vb->elementCount()) {
// cursor is past last element in bar, position of cursor is
// halfway between last element and end of bar
if (vb->elementCount() == 0) {
// unless entire voicebar is still empty
p.rx() += 15.0;
} else {
VoiceElement* ve = vb->element(vb->elementCount()-1);
p.rx() += (ve->x() + bar->size()) / 2;
}
} else {
// cursor is on an element, get the position of that element
p.rx() += vb->element(cursor.element())->x();
}
p.ry() += (cursor.staff()->lineCount() - 1)* cursor.staff()->lineSpacing();
p.ry() -= cursor.staff()->lineSpacing() * cursor.line() / 2;
m_tool->shape()->renderer()->renderNote(painter, m_duration < QuarterNote ? QuarterNote : m_duration, p, 0, Qt::magenta);
}
示例2: mousePress
void NoteEntryAction::mousePress(Staff* staff, int bar, const QPointF& pos)
{
Clef* clef = staff->lastClefChange(bar);
Voice* voice = staff->part()->voice(m_tool->voice());
VoiceBar* vb = voice->bar(bar);
// find element before which to insert the chord
int before = 0;
for (int i = 0; i < vb->elementCount(); i++) {
VoiceElement* e = vb->element(i);
if (e->x() >= pos.x()) break;
before++;
}
int line = staff->line(pos.y());
int pitch = 0, accidentals = 0;
if (clef && !m_isRest) {
pitch = clef->lineToPitch(line);
// get correct accidentals for note
KeySignature* ks = staff->lastKeySignatureChange(bar);
if (ks) accidentals = ks->accidentals(pitch);
for (int i = 0; i < before; i++) {
Chord* c = dynamic_cast<Chord*>(vb->element(i));
if (!c) continue;
for (int n = 0; n < c->noteCount(); n++) {
if (c->note(n)->pitch() == pitch) {
accidentals = c->note(n)->accidentals();
}
}
}
}
Chord* join = NULL;
if (before > 0) join = dynamic_cast<Chord*>(vb->element(before-1));
if (join && join->x() + join->width() >= pos.x()) {
if (clef && !m_isRest) {
m_tool->addCommand(new AddNoteCommand(m_tool->shape(), join, staff, m_duration, pitch, accidentals));
} else {
m_tool->addCommand(new MakeRestCommand(m_tool->shape(), join));
}
} else {
if (clef && !m_isRest) {
m_tool->addCommand(new CreateChordCommand(m_tool->shape(), vb, staff, m_duration, before, pitch, accidentals));
} else {
m_tool->addCommand(new CreateChordCommand(m_tool->shape(), vb, staff, m_duration, before));
}
}
}
示例3: mousePress
void AbstractNoteMusicAction::mousePress(Staff* staff, int barIdx, const QPointF& pos)
{
Part* part = staff->part();
Sheet* sheet = part->sheet();
Bar* bar = sheet->bar(barIdx);
Clef* clef = staff->lastClefChange(barIdx, 0);
// loop over all noteheads
qreal closestDist = 1e9;
Note* closestNote = 0;
Chord* chord = 0;
// outer loop, loop over all voices
for (int v = 0; v < part->voiceCount(); v++) {
Voice* voice = part->voice(v);
VoiceBar* vb = voice->bar(bar);
// next loop over all chords
for (int e = 0; e < vb->elementCount(); e++) {
Chord* c = dynamic_cast<Chord*>(vb->element(e));
if (!c) continue;
qreal centerX = c->x() + (c->width() / 2);
// check if it is a rest
if (c->noteCount() == 0) {
qreal centerY = c->y() + (c->height() / 2);
qreal dist = sqrt(sqr(centerX - pos.x()) + sqr(centerY - pos.y()));
if (dist < closestDist) {
closestDist = dist;
closestNote = NULL;
chord = c;
}
}
// lastly loop over all noteheads
for (int n = 0; n < c->noteCount(); n++) {
Note* note = c->note(n);
if (note->staff() != staff) continue;
int line = clef->pitchToLine(note->pitch());
qreal centerY = line * staff->lineSpacing() / 2;
qreal dist = sqrt(sqr(centerX - pos.x()) + sqr(centerY - pos.y()));
if (dist < closestDist) {
closestDist = dist;
closestNote = note;
chord = c;
}
}
}
}
StaffElement* se = 0;
for (int e = 0; e < bar->staffElementCount(staff); e++) {
StaffElement* elem = bar->staffElement(staff, e);
qreal centerX = elem->x() + (elem->width() / 2);
qreal centerY = elem->y() + (elem->height() / 2);
qreal dist = sqrt(sqr(centerX - pos.x()) + sqr(centerY - pos.y()));
if (dist < closestDist) {
se = elem;
closestDist = dist;
}
}
if (se) {
mousePress(se, closestDist, pos);
} else {
mousePress(chord, closestNote, closestDist, pos);
}
}