Skip to content

Commit

Permalink
updates for hairpins, dynamics
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Aug 2, 2016
1 parent f15aa95 commit d4cc062
Show file tree
Hide file tree
Showing 20 changed files with 364 additions and 148 deletions.
12 changes: 6 additions & 6 deletions fluid/voice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,12 +772,12 @@ void Voice::voice_start()
/* Make an estimate on how loud this voice can get at any time (attenuation). */
min_attenuation_cB = get_lower_boundary_for_attenuation();

qDebug("DELAY (%d) %d", FLUID_VOICE_ENVDELAY,volenv_data[FLUID_VOICE_ENVDELAY].count);
qDebug("ATTACK (%d) %d", FLUID_VOICE_ENVATTACK,volenv_data[FLUID_VOICE_ENVATTACK].count);
qDebug("HOLD (%d) %d", FLUID_VOICE_ENVHOLD, volenv_data[FLUID_VOICE_ENVHOLD].count);
qDebug("DECAY (%d) %d", FLUID_VOICE_ENVDECAY, volenv_data[FLUID_VOICE_ENVDECAY].count);
qDebug("SUSTAIN (%d) %d", FLUID_VOICE_ENVSUSTAIN, volenv_data[FLUID_VOICE_ENVSUSTAIN].count);
qDebug("RELEASE (%d) %d", FLUID_VOICE_ENVRELEASE, volenv_data[FLUID_VOICE_ENVRELEASE].count);
// qDebug("DELAY (%d) %d", FLUID_VOICE_ENVDELAY,volenv_data[FLUID_VOICE_ENVDELAY].count);
// qDebug("ATTACK (%d) %d", FLUID_VOICE_ENVATTACK,volenv_data[FLUID_VOICE_ENVATTACK].count);
// qDebug("HOLD (%d) %d", FLUID_VOICE_ENVHOLD, volenv_data[FLUID_VOICE_ENVHOLD].count);
// qDebug("DECAY (%d) %d", FLUID_VOICE_ENVDECAY, volenv_data[FLUID_VOICE_ENVDECAY].count);
// qDebug("SUSTAIN (%d) %d", FLUID_VOICE_ENVSUSTAIN, volenv_data[FLUID_VOICE_ENVSUSTAIN].count);
// qDebug("RELEASE (%d) %d", FLUID_VOICE_ENVRELEASE, volenv_data[FLUID_VOICE_ENVRELEASE].count);

/* Force setting of the phase at the first DSP loop run
* This cannot be done earlier, because it depends on modulators.
Expand Down
14 changes: 6 additions & 8 deletions libmscore/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,8 @@ void Score::expandVoice(Segment* s, int track)
qDebug("expand voice: no segment");
return;
}
if (s->element(track)) {
ChordRest* cr = (ChordRest*)(s->element(track));
qDebug("expand voice: found %s %s", cr->name(), qPrintable(cr->duration().print()));
if (s->element(track))
return;
}

// find previous segment with cr in this track
Segment* ps;
Expand All @@ -352,7 +349,7 @@ void Score::expandVoice(Segment* s, int track)
qDebug("expandVoice: cannot insert element here");
return;
}
if (cr->type() == Element::Type::CHORD) {
if (cr->isChord()) {
// previous cr ends on or before current segment
// for chords, move ps to just after cr ends
// so we can fill any gap that might exist
Expand Down Expand Up @@ -2246,9 +2243,10 @@ void Score::cmd(const QAction* a)
else if (cmd == "delete-measures")
cmdDeleteSelectedMeasures();
else if (cmd == "time-delete") {
// TODO:
// remove measures if stave-range is 0-nstaves()
cmdDeleteSelectedMeasures();
if (selection().state() == SelState::RANGE)
cmdDeleteSelectedMeasures();
else
cmdTimeDelete();
}
else if (cmd == "pitch-up-octave") {
if (el && (el->isArticulation() || el->isText()))
Expand Down
16 changes: 3 additions & 13 deletions libmscore/dynamic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,6 @@ Dynamic::Dynamic(const Dynamic& d)
_dynRange = d._dynRange;
}

//---------------------------------------------------------
// setVelocity
//---------------------------------------------------------

void Dynamic::setVelocity(int v)
{
_velocity = v;
}

//---------------------------------------------------------
// velocity
//---------------------------------------------------------
Expand Down Expand Up @@ -193,7 +184,6 @@ void Dynamic::layout()
// doAutoplace
//
// Move Dynamic up or down to avoid collisions with other elements.
// Minimum vertical distance is one spatium.
//-------------------------------------------------------------------

void Dynamic::doAutoplace()
Expand All @@ -202,7 +192,7 @@ void Dynamic::doAutoplace()
if (!(s && autoplace()))
return;

qreal minDistance = spatium();
qreal minDistance = score()->styleP(StyleIdx::dynamicsMinDistance);
Shape s1 = s->staffShape(staffIdx()).translated(s->pos());
Shape s2 = shape().translated(s->pos());

Expand Down Expand Up @@ -310,7 +300,7 @@ QRectF Dynamic::drag(EditData* ed)

void Dynamic::undoSetDynRange(Range v)
{
score()->undoChangeProperty(this, P_ID::DYNAMIC_RANGE, int(v));
undoChangeProperty(P_ID::DYNAMIC_RANGE, int(v));
}

//---------------------------------------------------------
Expand All @@ -319,7 +309,7 @@ void Dynamic::undoSetDynRange(Range v)

QVariant Dynamic::getProperty(P_ID propertyId) const
{
switch(propertyId) {
switch (propertyId) {
case P_ID::DYNAMIC_RANGE: return int(_dynRange);
case P_ID::VELOCITY: return velocity();
case P_ID::SUBTYPE: return int(_dynamicType);
Expand Down
2 changes: 1 addition & 1 deletion libmscore/dynamic.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class Dynamic : public Text {
virtual void endEdit() override;
virtual void reset() override;

void setVelocity(int v);
void setVelocity(int v) { _velocity = v; }
int velocity() const;
Range dynRange() const { return _dynRange; }
void setDynRange(Range t) { _dynRange = t; }
Expand Down
133 changes: 107 additions & 26 deletions libmscore/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,38 +898,61 @@ void Score::cmdRemoveTimeSig(TimeSig* ts)
}
}
}

//---------------------------------------------------------
// cmdAddPitch
// cmdTimeDelete
//---------------------------------------------------------

void Score::cmdAddPitch(int step, bool addFlag)
void Score::cmdTimeDelete()
{
startCmd();
addPitch(step, addFlag);
endCmd();
qDebug("time delete");
Element* el = selection().element();
if (!(el || el->isNote()))
return;
Note* note = toNote(el);
Chord* chord = note->chord();
Segment* seg = chord->segment();
int tick = seg->tick();
Fraction f = chord->duration();
int len = f.ticks();
while (seg) {
if (seg->tick() >= tick + len)
break;
Segment* nseg = seg->next();
undoRemoveElement(seg);
seg = nseg;
}
undoInsertTime(tick, -len);
undo(new InsertTime(this, tick, -len));
for (Segment* s = seg; s; s = s-> next())
s->undoChangeProperty(P_ID::TICK, s->rtick() - len);
Measure* m = chord->measure();
undo(new ChangeMeasureLen(m, m->len() - f));
}

//---------------------------------------------------------
// addPitch
// cmdAddPitch
//---------------------------------------------------------

void Score::addPitch(int step, bool addFlag)
void Score::cmdAddPitch(int step, bool addFlag, bool insert)
{
startCmd();
Position pos;
if (addFlag) {
Element* el = selection().element();
if (el && el->isNote()) {
Note* selectedNote = toNote(el);
pos.segment = selectedNote->chord()->segment();
Chord* chord = selectedNote->chord();
Segment* seg = chord->segment();
pos.segment = seg;
pos.staffIdx = selectedNote->track() / VOICES;
ClefType clef = staff(pos.staffIdx)->clef(pos.segment->tick());
ClefType clef = staff(pos.staffIdx)->clef(seg->tick());
pos.line = relStep(step, clef);
Chord* chord = toNote(el)->chord();
bool error;
NoteVal nval = noteValForPosition(pos, error);
if (error)
if (error) {
endCmd();
return;
}
addNote(chord, nval);
endCmd();
return;
Expand All @@ -944,7 +967,8 @@ void Score::addPitch(int step, bool addFlag)
if (inputState().repitchMode())
repitchNote(pos, !addFlag);
else
putNote(pos, !addFlag);
putNote(pos, !addFlag, insert);
endCmd();
}

//---------------------------------------------------------
Expand Down Expand Up @@ -1188,7 +1212,7 @@ Note* Score::addPitch(NoteVal& nval, bool addFlag)
// mouse click in state NoteType::ENTRY
//---------------------------------------------------------

void Score::putNote(const QPointF& pos, bool replace)
void Score::putNote(const QPointF& pos, bool replace, bool insert)
{
Position p;
if (!getPosition(&p, pos, _is.voice())) {
Expand All @@ -1198,11 +1222,15 @@ void Score::putNote(const QPointF& pos, bool replace)
if (inputState().repitchMode())
repitchNote(p, replace);
else
putNote(p, replace);
putNote(p, replace, insert);
}

void Score::putNote(const Position& p, bool replace)
void Score::putNote(const Position& p, bool replace, bool insert)
{
if (insert) {
putNoteInsert(p);
return;
}
int staffIdx = p.staffIdx;
Staff* st = staff(staffIdx);
Segment* s = p.segment;
Expand All @@ -1217,19 +1245,16 @@ void Score::putNote(const Position& p, bool replace)
return;

const StringData* stringData = 0;
const Instrument* instr = st->part()->instrument(s->tick());
switch (st->staffType()->group()) {
case StaffGroup::PERCUSSION: {
const Drumset* ds = instr->drumset();
const Drumset* ds = st->part()->instrument(s->tick())->drumset();
stemDirection = ds->stemDirection(nval.pitch);
break;
}
case StaffGroup::TAB: {
stringData = instr->stringData();
}
case StaffGroup::TAB:
stringData = st->part()->instrument(s->tick())->stringData();
break;
case StaffGroup::STANDARD: {
}
case StaffGroup::STANDARD:
break;
}

Expand Down Expand Up @@ -1298,6 +1323,59 @@ void Score::putNote(const Position& p, bool replace)
_is.moveToNextInputPos();
}

//---------------------------------------------------------
// putNoteInsert
//---------------------------------------------------------

void Score::putNoteInsert(const Position& pos)
{
// insert
// TODO:
// - check voices
// - split chord/rest

Element* el = selection().element();
if (!el)
return;
if (!(el->isNote() || el->isRest()))
return;
ChordRest* cr = el->isNote() ? toChordRest(toNote(el)->chord()) : toChordRest(el);
TDuration duration = cr->actualDurationType();
Fraction fraction = cr->duration();
int len = fraction.ticks();
Segment* seg = pos.segment;
int tick = seg->tick();
Measure* m = seg->measure();

for (int track = 0; track < _staves.size() * VOICES; ++track) {
Element* e = seg->element(track);
if (e && e->isChordRest()) {
ChordRest* cr = toChordRest(e);
if (cr->tuplet() && cr->tuplet()->elements().front() != cr) {
qDebug("cannot insert in tuplet");
return;
}
}
}

undoInsertTime(tick, len);
undo(new InsertTime(this, tick, len));
for (Segment* s = pos.segment; s; s = s-> next())
s->undoChangeProperty(P_ID::TICK, s->rtick() + len);
undo(new ChangeMeasureLen(m, m->len() + fraction));

Segment* s = m->undoGetSegment(Segment::Type::ChordRest, tick);
Position p(pos);
p.segment = s;

for (int si = 0; si < _staves.size(); ++si) {
if (si == p.staffIdx)
putNote(p, true, false);
else
addRest(s, si * VOICES, duration, nullptr);
}
}

//---------------------------------------------------------
// repitchNote
//---------------------------------------------------------
Expand Down Expand Up @@ -1915,16 +1993,18 @@ void Score::deleteItem(Element* el)
undoRemoveElement(el);
break;

case Element::Type::BAR_LINE:
{
case Element::Type::BAR_LINE: {
BarLine* bl = toBarLine(el);
Segment* seg = bl->segment();
Measure* m = seg->measure();
Segment::Type segType = seg->segmentType();

if (segType & (Segment::Type::BarLine | Segment::Type::BeginBarLine))
if (segType & (Segment::Type::BeginBarLine | Segment::Type::BarLine))
undoRemoveElement(el);
else if (segType == Segment::Type::EndBarLine) {
endCmd();
cmdJoinMeasure(m, m->nextMeasure());
#if 0
m->undoResetProperty(P_ID::REPEAT_END);
Measure* nm = m->nextMeasure();
if (nm && m->system() == nm->system())
Expand All @@ -1939,6 +2019,7 @@ void Score::deleteItem(Element* el)
b->undoResetProperty(P_ID::BARLINE_SPAN_FROM);
b->undoResetProperty(P_ID::BARLINE_SPAN_TO);
}
#endif
}
else if (segType == Segment::Type::StartRepeatBarLine)
m->undoChangeProperty(P_ID::REPEAT_START, false);
Expand Down
Loading

0 comments on commit d4cc062

Please sign in to comment.