Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/importexport/tabledit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ set(MODULE_SRC

${CMAKE_CURRENT_LIST_DIR}/internal/importtef.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/importtef.h
${CMAKE_CURRENT_LIST_DIR}/internal/measurehandler.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/measurehandler.h
${CMAKE_CURRENT_LIST_DIR}/internal/note.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/note.h
${CMAKE_CURRENT_LIST_DIR}/internal/tuplethandler.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/tuplethandler.h
${CMAKE_CURRENT_LIST_DIR}/internal/voiceallocator.cpp
Expand Down
123 changes: 108 additions & 15 deletions src/importexport/tabledit/internal/importtef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "importtef.h"
#include "measurehandler.h"
#include "tuplethandler.h"

#include "engraving/dom/box.h"
Expand Down Expand Up @@ -265,19 +266,20 @@
chord->add(cr);
}

static void addRest(Segment* segment, track_idx_t track, TDuration tDuration, Fraction length, muse::draw::Color color)
static void addRest(Segment* segment, track_idx_t track, TDuration tDuration, Fraction length, muse::draw::Color color, bool visible = true)
{
mu::engraving::Rest* rest = Factory::createRest(segment);
if (rest) {
rest->setTrack(track);
rest->setDurationType(tDuration);
rest->setTicks(length);
rest->setColor(color);
rest->setVisible(visible);
segment->add(rest);
}
}

void TablEdit::createContents()
void TablEdit::createContents(const MeasureHandler& measureHandler)
{
if (tefInstruments.size() == 0) {
LOGD("error: no instruments");
Expand Down Expand Up @@ -315,10 +317,14 @@
if (firstNote->dots) {
tDuration.setDots(firstNote->dots);
}

const auto idx { measureHandler.measureIndex(firstNote->position, tefMeasures) };
const Fraction gapCorrection { measureHandler.sumPreviousGaps(idx), 64 };
const auto positionCorrection = tupletHandler.doTuplet(firstNote);

Fraction tick { firstNote->position, 64 }; // position is in 64th
tick += positionCorrection;
tick -= gapCorrection;
LOGN(" positionCorrection %d/%d tick %d/%d length %d/%d",
positionCorrection.numerator(), positionCorrection.denominator(),
tick.numerator(), tick.denominator(),
Expand Down Expand Up @@ -413,19 +419,38 @@
}
}

void TablEdit::createMeasures()
static Fraction reducedActualLength(const int actual, const int nominalDenominator)
{
Fraction res { actual, 64 };
while (res.denominator() >= 2 * nominalDenominator && res.numerator() % 2 == 0) {
res.setNumerator(res.numerator() / 2);
res.setDenominator(res.denominator() / 2);
}
LOGN("actual %d nominalDenominator %d res %d/%d", actual, nominalDenominator, res.numerator(), res.denominator());
return res;
}

void TablEdit::createMeasures(const MeasureHandler& measureHandler)
{
int lastKey { 0 }; // safe default
Fraction lastTimeSig { -1, -1 }; // impossible value
Fraction tick { 0, 1 };
for (const auto& tefMeasure : tefMeasures) {
for (size_t idx = 0; idx < tefMeasures.size(); ++idx) {
TefMeasure& tefMeasure { tefMeasures.at(idx) };
// create measure
auto measure = Factory::createMeasure(score->dummy()->system());
measure->setTick(tick);
Fraction length{ tefMeasure.numerator, tefMeasure.denominator };
measure->setTimesig(length);
measure->setTicks(length);
Fraction nominalLength{ tefMeasure.numerator, tefMeasure.denominator };
Fraction actualLength{ reducedActualLength(measureHandler.actualSize(tefMeasures, idx), tefMeasure.denominator) };
measure->setTimesig(nominalLength);
measure->setTicks(actualLength);
measure->setEndBarLineType(BarLineType::NORMAL, 0);
LOGN("measure %p tick %d/%d nominalLength %d/%d actualLength %d/%d",
measure,
tick.numerator(), tick.denominator(),
nominalLength.numerator(), nominalLength.denominator(),
actualLength.numerator(), actualLength.denominator()
);
score->measures()->add(measure);

if (tick == Fraction { 0, 1 }) {
Expand All @@ -441,11 +466,11 @@
auto s2 = measure->getSegment(mu::engraving::SegmentType::TimeSig, tick);
for (size_t i = 0; i < tefInstruments.size(); ++i) {
mu::engraving::TimeSig* timesig = Factory::createTimeSig(s2);
timesig->setSig(length);
timesig->setSig(nominalLength);
timesig->setTrack(i * VOICES);
s2->add(timesig);
}
lastTimeSig = length;
lastTimeSig = nominalLength;
createTempo();
} else {
if (tefMeasure.key != lastKey) {
Expand All @@ -458,19 +483,19 @@
}
lastKey = tefMeasure.key;
}
if (length != lastTimeSig) {
if (nominalLength != lastTimeSig) {
auto s2 = measure->getSegment(mu::engraving::SegmentType::TimeSig, tick);
for (size_t i = 0; i < tefInstruments.size(); ++i) {
mu::engraving::TimeSig* timesig = Factory::createTimeSig(s2);
timesig->setSig(length);
timesig->setSig(nominalLength);
timesig->setTrack(i * VOICES);
s2->add(timesig);
}
lastTimeSig = length;
lastTimeSig = nominalLength;
}
}

tick += length;
tick += actualLength;
}
score->setUpTempoMap();
}
Expand Down Expand Up @@ -569,14 +594,81 @@
}
}

//---------------------------------------------------------
// fillGap
//---------------------------------------------------------

// Fill one gap (tstart - tend) in this track in this measure with rest(s).

static void fillGap(Measure* measure, track_idx_t track, const Fraction& tstart, const Fraction& tend)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Measure has a method fillGap, maybe you can use that, but you do need to add a parameter to make the rests invisible
  • If you prefer using a dedicated static function, then you could perhaps still benefit from the toRhythmicDurationList utility, or maybe just toDurationList, both are in durationtype.h.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer not to use a dedicated function, but could not find a suitable one ... Note that I do not consider rest visibility important in gaps.

{
Fraction ctick = tstart;
Fraction restLen = tend - tstart;
LOGN("measure %p track %zu tstart %d tend %d restLen %d len",
measure, track, tstart.ticks(), tend.ticks(), restLen.ticks());
auto durList = toDurationList(restLen, true);
LOGN("durList.size %zu", durList.size());
for (const auto& dur : durList) {
LOGN("type %d dots %d fraction %d/%d", dur.type(), dur.dots(), dur.fraction().numerator(), dur.fraction().denominator());

Check warning on line 612 in src/importexport/tabledit/internal/importtef.cpp

View workflow job for this annotation

GitHub Actions / build (linux_arm64)

format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘mu::engraving::DurationType’ [-Wformat=]

Check warning on line 612 in src/importexport/tabledit/internal/importtef.cpp

View workflow job for this annotation

GitHub Actions / build (linux_x64)

format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘mu::engraving::DurationType’ [-Wformat=]
Segment* s = measure->getSegment(SegmentType::ChordRest, ctick);
addRest(s, track, dur, dur.fraction(), muse::draw::Color::BLACK, false);
ctick += dur.fraction();
}
}

//---------------------------------------------------------
// fillGapsInFirstVoices
//---------------------------------------------------------

// Fill gaps in first voice of every staff in this measure for this part with rest(s).

static void fillGapsInFirstVoices(MasterScore* score)
{
IF_ASSERT_FAILED(score) {
return;
}

for (staff_idx_t idx = 0; idx < score->nstaves(); ++idx) {
for (Measure* measure = score->firstMeasure(); measure; measure = measure->nextMeasure()) {
Fraction measTick = measure->tick();
Fraction measLen = measure->ticks();
Fraction nextMeasTick = measTick + measLen;
LOGN("measure %p idx %zu tick %d - %d (len %d)",
measure, idx, measTick.ticks(), nextMeasTick.ticks(), measLen.ticks());
track_idx_t track = idx * VOICES;
Fraction endOfLastCR = measTick;
for (Segment* s = measure->first(); s; s = s->next()) {
EngravingItem* el = s->element(track);
if (el) {
if (s->isChordRestType()) {
ChordRest* cr = static_cast<ChordRest*>(el);
Fraction crTick = cr->tick();
Fraction crLen = cr->globalTicks();
if (crTick > endOfLastCR) {
fillGap(measure, track, endOfLastCR, crTick);
}
endOfLastCR = crTick + crLen;
}
}
}
if (nextMeasTick > endOfLastCR) {
fillGap(measure, track, endOfLastCR, nextMeasTick);
}
}
}
}

void TablEdit::createScore()
{
MeasureHandler measureHandler;
measureHandler.calculate(tefContents, tefMeasures);
createProperties();
createParts();
createTitleFrame();
createMeasures();
createMeasures(measureHandler);
createNotesFrame();
createContents();
createContents(measureHandler);
fillGapsInFirstVoices(score);
createRepeats();
createTexts();
createLinkedTabs();
Expand Down Expand Up @@ -877,6 +969,7 @@
for (uint16_t i = 0; i < numberOfMeasures; ++i) {
TefMeasure measure;
measure.flag = readUInt8();
measure.isPickup = measure.flag & 0x08;
/* uint8_t uTmp = */ readUInt8();
measure.key = readInt8();
measure.size = readUInt8();
Expand Down
23 changes: 13 additions & 10 deletions src/importexport/tabledit/internal/importtef.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "voiceallocator.h"

namespace mu::iex::tabledit {
class MeasureHandler;

// offsets into the file header
static const uint8_t OFFSET_TBED = 0x38;
static const uint8_t OFFSET_CONTENTS = 0x3C;
Expand All @@ -54,6 +56,15 @@ enum class Voice : uint8_t {
LOWER = 3 // lower set
};

struct TefMeasure {
int flag { 0 };
bool isPickup { false };
int key { 0 };
int size { 0 };
int numerator { 0 };
int denominator { 0 };
};

struct TefNote {
int position { 0 };
int string { 0 };
Expand Down Expand Up @@ -120,14 +131,6 @@ class TablEdit
std::string name;
};

struct TefMeasure {
int flag { 0 };
int key { 0 };
int size { 0 };
int numerator { 0 };
int denominator { 0 };
};

struct TefReadingListItem {
int firstMeasure { 0 };
int lastMeasure { 0 };
Expand All @@ -140,9 +143,9 @@ class TablEdit
};

void allocateVoices(std::vector<VoiceAllocator>& allocator);
void createContents();
void createContents(const MeasureHandler& measureHandler);
void createLinkedTabs();
void createMeasures();
void createMeasures(const MeasureHandler& measureHandler);
void createNotesFrame();
void createParts();
void createProperties();
Expand Down
Loading
Loading