Deluge Firmware 1.3.0
Build date: 2026.11.28
Loading...
Searching...
No Matches
NoteRegrouper Class Reference

#include <note_regrouper.h>

Collaboration diagram for NoteRegrouper:

Public Member Functions

 NoteRegrouper (InstrumentClip &clip, ModelStackWithTimelineCounter *modelStack)
 The song's key (modelStack->song->key) must still be the one from before the change.
bool regroup (const ScaleChange &change, deluge::accidentals::AccidentalHandling handling, int32_t pendingTranspose=0)

Private Types

using RowFlags = deluge::vector<uint8_t>
 One flag per NoteRow: whether its pitch was in the key before the change.

Private Member Functions

bool moveWholeRows (const ScaleChange &change, const MusicalKey &oldKey, const MusicalKey &finalKey, int32_t pendingTranspose)
bool sortAndMergeRows (RowFlags &wasInScale)
void moveRow (NoteRow *row, int32_t rowIndex, int32_t newY)

Private Attributes

InstrumentClip & clip_
ModelStackWithTimelineCounter * modelStack_

Detailed Description

Moves the notes of a scale-mode clip for a scale change which shifts or remaps scale degrees.

Notes are moved one at a time (see model/scale/accidentals.h), so that notes which an earlier scale change put in the same NoteRow split back out again. In-key notes go where their scale degree goes; accidentals (notes outside the scale, or carrying an AnchorMarker) go where their anchor takes them. Rows can then land on or cross each other, so the rows are sorted again and rows with the same pitch merged.

None of this is undoable.

Member Function Documentation

◆ moveWholeRows()

bool NoteRegrouper::moveWholeRows ( const ScaleChange & change,
const MusicalKey & oldKey,
const MusicalKey & finalKey,
int32_t pendingTranspose )
private

The cheap way, for a clip with no accidentals: every row moves as a whole by its scale degree's shift, with no memory allocated and no note touched. Returns false, having changed nothing, unless that is exactly what the per-note way would do, which is when:

  • the change shifts scale degrees (no letter mapping), so an in-key note which is its own anchor goes to pitch + change[degree] and stays its own anchor;
  • every row is in the old key and no note has a marker, so that is every note, and none leaves its row;
  • every row lands in the final key, so every note's marker stays "derived";
  • the rows stay in strictly ascending order, so there is nothing to sort or merge.

◆ regroup()

bool NoteRegrouper::regroup ( const ScaleChange & change,
deluge::accidentals::AccidentalHandling handling,
int32_t pendingTranspose = 0 )
nodiscard

Applies the change, whose target is the scale after it. Doesn't touch the clip's yScroll.

pendingTranspose is a uniform shift in semitones which the caller is still to apply to every row and to the key's root afterwards (in-key transposition does this): markers are chosen for the key as it will be then.

Returns whether rows were restructured: notes changed NoteRow, or rows merged. Undo history made before that finds its notes by row, so it is stale and must not be reverted (see ActionLogger::invalidateLogs()).

◆ sortAndMergeRows()

bool NoteRegrouper::sortAndMergeRows ( RowFlags & wasInScale)
private

Restores ascending y order of the rows (which are binary-searched) after they have been moved, and merges rows which ended up with the same y. The survivor of a merge is the row that was in scale, else the one with more notes. Returns whether any rows were merged.


The documentation for this class was generated from the following files:
  • src/deluge/model/clip/note_regrouper.h
  • src/deluge/model/clip/note_regrouper.cpp