// Copyright: 2024, Ableton AG, Berlin. All rights reserved. import QtQml 2.2 import Ableton.Grid 1.0 as Grid import "beatTimeGridUtils.js" as BeatTimeGridUtils /** * Carries the description of a BeatTimeGrid * * This is the model for the grid, used by controllers and widgets to * operate the grid properties from the outside. */ Grid.BeatTimeGridPropertiesData { id: root enabled: true tripletsDesired: false signatureNumerator: 4 signatureDenominator: 4 barDurationInBeats: BeatTimeGridUtils.barDurationInBeats( root.signatureNumerator, root.signatureDenominator ) gridIntervalInBeats: root.gridInterval.toBeatTime( root.barDurationInBeats ) property var gridInterval: BeatTimeGridUtils.gridIntervalFromNoteFraction(4) readonly property int minNoteFractionBeforeSwitchingToBars: 2 readonly property int minBarsBeforeSwitchingToNotes: 1 function toggle() { root.enabled = !root.enabled; } function narrow() { var newInterval; if(gridInterval.unit === 'bar') { if(gridInterval.value === minBarsBeforeSwitchingToNotes) { newInterval = BeatTimeGridUtils.gridIntervalFromNoteFraction(minNoteFractionBeforeSwitchingToBars, tripletsDesired); } else { newInterval = BeatTimeGridUtils.gridIntervalFromBars(gridInterval.value / 2.0); } } else { newInterval = BeatTimeGridUtils.gridIntervalFromNoteFraction(gridInterval.value * 2.0, tripletsDesired); } setGridInterval(newInterval); } function widen() { var newInterval; if(gridInterval.unit === 'note' || gridInterval.unit === 'noteT') { if(gridInterval.value === minNoteFractionBeforeSwitchingToBars) { newInterval = BeatTimeGridUtils.gridIntervalFromBars(minBarsBeforeSwitchingToNotes); } else { newInterval = BeatTimeGridUtils.gridIntervalFromNoteFraction(gridInterval.value / 2.0, tripletsDesired); } } else { newInterval = BeatTimeGridUtils.gridIntervalFromBars(gridInterval.value * 2.0); } setGridInterval(newInterval); } function setTripletsDesired(value) { if (root.tripletsDesired === value) { return; } root.tripletsDesired = value; if(gridInterval.unit === 'bar') { setGridInterval(BeatTimeGridUtils.gridIntervalFromBars( gridInterval.value)); } else { setGridInterval(BeatTimeGridUtils.gridIntervalFromNoteFraction( gridInterval.value, tripletsDesired)); } } function setEnabled(value) { if (root.enabled === value) { return; } root.enabled = value; } /** * set the basic interval of the grid * @param Ableton::Grid::BeatTimeGrid::GridInterval gridInterval */ function setGridInterval(gridInterval) { if (BeatTimeGridUtils.compareGridIntervals(root.gridInterval, gridInterval) === 0) { return; } if (gridInterval == 'noteT') { root.tripletsDesired = true; } root.gridInterval = gridInterval; } function setSignatureNumerator(value) { if (root.signatureNumerator === value) { return; } root.signatureNumerator = value; } function setSignatureDenominator(value) { if (root.signatureDenominator === value) { return; } root.signatureDenominator = value; } }