Skip to content

Commit

Permalink
Merge pull request #6248 from jeetee/refactor_score_unwinding
Browse files Browse the repository at this point in the history
Refactor score unwinding
  • Loading branch information
anatoly-os committed Aug 25, 2020
2 parents b086737 + 246fc0d commit 375b47e
Show file tree
Hide file tree
Showing 70 changed files with 5,096 additions and 10,935 deletions.
36 changes: 18 additions & 18 deletions libmscore/rendermidi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ static void aeolusSetStop(int tick, int channel, int i, int k, bool val, EventMa
// collectProgramChanges
//---------------------------------------------------------

static void collectProgramChanges(EventMap* events, Measure* m, Staff* staff, int tickOffset)
static void collectProgramChanges(EventMap* events, Measure const * m, Staff* staff, int tickOffset)
{
int firstStaffIdx = staff->idx();
int nextStaffIdx = firstStaffIdx + 1;
Expand Down Expand Up @@ -532,7 +532,7 @@ static int getControllerFromCC(int cc)
// renderHarmony
/// renders chord symbols
//---------------------------------------------------------
static void renderHarmony(EventMap* events, Measure* m, Harmony* h, int tickOffset)
static void renderHarmony(EventMap* events, Measure const * m, Harmony* h, int tickOffset)
{
if (!h->isRealizable())
return;
Expand Down Expand Up @@ -576,7 +576,7 @@ static void renderHarmony(EventMap* events, Measure* m, Harmony* h, int tickOffs
// the original, velocity-only method of collecting events.
//---------------------------------------------------------

void MidiRenderer::collectMeasureEventsSimple(EventMap* events, Measure* m, const StaffContext& sctx, int tickOffset)
void MidiRenderer::collectMeasureEventsSimple(EventMap* events, Measure const * m, const StaffContext& sctx, int tickOffset)
{
int firstStaffIdx = sctx.staff->idx();
int nextStaffIdx = firstStaffIdx + 1;
Expand Down Expand Up @@ -655,7 +655,7 @@ void MidiRenderer::collectMeasureEventsSimple(EventMap* events, Measure* m, cons
// SEG_START - note-on velocity is the same as the start velocity of the seg
//---------------------------------------------------------

void MidiRenderer::collectMeasureEventsDefault(EventMap* events, Measure* m, const StaffContext& sctx, int tickOffset)
void MidiRenderer::collectMeasureEventsDefault(EventMap* events, Measure const * m, const StaffContext& sctx, int tickOffset)
{
int controller = getControllerFromCC(sctx.cc);

Expand Down Expand Up @@ -748,7 +748,7 @@ void MidiRenderer::collectMeasureEventsDefault(EventMap* events, Measure* m, con
// redirects to the correct function based on the passed method
//---------------------------------------------------------

void MidiRenderer::collectMeasureEvents(EventMap* events, Measure* m, const StaffContext& sctx, int tickOffset)
void MidiRenderer::collectMeasureEvents(EventMap* events, Measure const * m, const StaffContext& sctx, int tickOffset)
{
switch (sctx.method) {
case DynamicsRenderMethod::SIMPLE:
Expand Down Expand Up @@ -917,13 +917,13 @@ void Score::updateVelo()

void MidiRenderer::renderStaffChunk(const Chunk& chunk, EventMap* events, const StaffContext& sctx)
{
Measure* start = chunk.startMeasure();
Measure* end = chunk.endMeasure();
Measure const * const start = chunk.startMeasure();
Measure const * const end = chunk.endMeasure();
const int tickOffset = chunk.tickOffset();

Measure* lastMeasure = start->prevMeasure();
Measure const * lastMeasure = start->prevMeasure();

for (Measure* m = start; m != end; m = m->nextMeasure()) {
for (Measure const * m = start; m != end; m = m->nextMeasure()) {
if (lastMeasure && m->isRepeatMeasure(sctx.staff)) {
int offset = (m->tick() - lastMeasure->tick()).ticks();
collectMeasureEvents(events, lastMeasure, sctx, tickOffset + offset);
Expand Down Expand Up @@ -2060,15 +2060,15 @@ void Score::createPlayEvents(Chord* chord)
// don't change event list if type is PlayEventType::User
}

void Score::createPlayEvents(Measure* start, Measure* end)
void Score::createPlayEvents(Measure const * start, Measure const * const end)
{
if (!start)
start = firstMeasure();

int etrack = nstaves() * VOICES;
for (int track = 0; track < etrack; ++track) {
bool rangeEnded = false;
for (Measure* m = start; m; m = m->nextMeasure()) {
for (Measure const * m = start; m; m = m->nextMeasure()) {
constexpr SegmentType st = SegmentType::ChordRest;

if (m == end)
Expand Down Expand Up @@ -2112,10 +2112,10 @@ void Score::createPlayEvents(Measure* start, Measure* end)
void MidiRenderer::renderMetronome(const Chunk& chunk, EventMap* events)
{
const int tickOffset = chunk.tickOffset();
Measure* start = chunk.startMeasure();
Measure* end = chunk.endMeasure();
Measure const * const start = chunk.startMeasure();
Measure const * const end = chunk.endMeasure();

for (Measure* m = start; m != end; m = m->nextMeasure())
for (Measure const * m = start; m != end; m = m->nextMeasure())
renderMetronome(events, m, Fraction::fromTicks(tickOffset));
}

Expand All @@ -2124,7 +2124,7 @@ void MidiRenderer::renderMetronome(const Chunk& chunk, EventMap* events)
/// add metronome tick events
//---------------------------------------------------------

void MidiRenderer::renderMetronome(EventMap* events, Measure* m, const Fraction& tickOffset)
void MidiRenderer::renderMetronome(EventMap* events, Measure const * m, const Fraction& tickOffset)
{
int msrTick = m->tick().ticks();
qreal tempo = score->tempomap()->tempo(msrTick);
Expand Down Expand Up @@ -2330,11 +2330,11 @@ void MidiRenderer::updateChunksPartition()
continue;
}

Measure* end = rs->lastMeasure()->nextMeasure();
Measure const * const end = rs->lastMeasure()->nextMeasure();
int count = 0;
bool needBreak = false;
Measure* chunkStart = nullptr;
for (Measure* m = rs->firstMeasure(); m != end; m = m->nextMeasure()) {
Measure const * chunkStart = nullptr;
for (Measure const * m = rs->firstMeasure(); m != end; m = m->nextMeasure()) {
if (!chunkStart)
chunkStart = m;
if ((++count) >= minChunkSize)
Expand Down
20 changes: 10 additions & 10 deletions libmscore/rendermidi.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,21 @@ class MidiRenderer {
public:
class Chunk {
int _tickOffset;
Measure* first;
Measure* last;
Measure const * first;
Measure const * last;

public:
Chunk(int tickOffset, Measure* fst, Measure* lst)
Chunk(int tickOffset, Measure const * fst, Measure const * lst)
: _tickOffset(tickOffset), first(fst), last(lst) {}

Chunk() // "invalid chunk" constructor
: _tickOffset(0), first(nullptr), last(nullptr) {}

operator bool() const { return bool(first); }
int tickOffset() const { return _tickOffset; }
Measure* startMeasure() const { return first; }
Measure* endMeasure() const { return last ? last->nextMeasure() : nullptr; }
Measure* lastMeasure() const { return last; }
Measure const * startMeasure() const { return first; }
Measure const * endMeasure() const { return last ? last->nextMeasure() : nullptr; }
Measure const * lastMeasure() const { return last; }
int tick1() const { return first->tick().ticks(); }
int tick2() const { return last ? last->endTick().ticks() : tick1(); }
int utick1() const { return tick1() + tickOffset(); }
Expand All @@ -107,11 +107,11 @@ class MidiRenderer {
void renderStaffChunk(const Chunk&, EventMap* events, const StaffContext& sctx);
void renderSpanners(const Chunk&, EventMap* events);
void renderMetronome(const Chunk&, EventMap* events);
void renderMetronome(EventMap* events, Measure* m, const Fraction& tickOffset);
void renderMetronome(EventMap* events, Measure const * m, const Fraction& tickOffset);

void collectMeasureEvents(EventMap* events, Measure* m, const MidiRenderer::StaffContext& sctx, int tickOffset);
void collectMeasureEventsSimple(EventMap* events, Measure* m, const StaffContext& sctx, int tickOffset);
void collectMeasureEventsDefault(EventMap* events, Measure* m, const StaffContext& sctx, int tickOffset);
void collectMeasureEvents(EventMap* events, Measure const * m, const MidiRenderer::StaffContext& sctx, int tickOffset);
void collectMeasureEventsSimple(EventMap* events, Measure const * m, const StaffContext& sctx, int tickOffset);
void collectMeasureEventsDefault(EventMap* events, Measure const * m, const StaffContext& sctx, int tickOffset);

public:
explicit MidiRenderer(Score* s) : score(s) {}
Expand Down
Loading

0 comments on commit 375b47e

Please sign in to comment.