Skip to content
This repository was archived by the owner on May 3, 2025. It is now read-only.

Commit 6b5da45

Browse files
🐛 Fix looping behavior in PianoRoll/Sequencer preview modes (#98)
* Merge updated stepCount from props in PianoRoll/Sequencer, set stepCount data attribute for style mutation to loop properly * Add keymirror package * Fix off-by-one error in index style mutation (subtract 1 from stepCount for index)
1 parent 628fb20 commit 6b5da45

File tree

11 files changed

+94
-39
lines changed

11 files changed

+94
-39
lines changed

package-lock.json

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"glamor": "2.20.40",
1919
"immutable": "4.0.0",
2020
"jotai": "1.5.2",
21+
"keymirror": "0.1.1",
2122
"lodash": "4.17.21",
2223
"luxon": "2.0.2",
2324
"opus-media-recorder": "0.8.0",
@@ -45,6 +46,7 @@
4546
"@types/chalk": "2.2.0",
4647
"@types/dotenv": "8.2.0",
4748
"@types/jest": "26.0.24",
49+
"@types/keymirror": "0.1.1",
4850
"@types/lodash": "4.14.172",
4951
"@types/luxon": "2.0.5",
5052
"@types/node": "12.20.19",

src/components/piano-roll/piano-roll.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { MidiNoteUtils } from "utils/midi-note-utils";
2020
import { MidiNote } from "types/midi-note";
2121
import { useToneAudio } from "utils/hooks/use-tone-audio";
2222
import { TrackRecord } from "models/track-record";
23+
import { toDataAttributes } from "utils/data-attribute-utils";
2324

2425
interface PianoRollProps {
2526
file?: FileRecord;
@@ -58,7 +59,7 @@ const PianoRoll: React.FC<PianoRollProps> = (props: PianoRollProps) => {
5859
instruments: instrument != null ? List.of(instrument) : undefined,
5960
files: file != null ? List.of(file) : undefined,
6061
tracks: List.of(track),
61-
trackSections: List.of(trackSection),
62+
trackSections: List.of(trackSection.merge({ step_count: stepCount })),
6263
trackSectionSteps,
6364
});
6465

@@ -72,7 +73,7 @@ const PianoRoll: React.FC<PianoRollProps> = (props: PianoRollProps) => {
7273
);
7374

7475
return (
75-
<React.Fragment>
76+
<Pane {...toDataAttributes({ stepCount })}>
7677
<Pane marginBottom={majorScale(1)}>
7778
<PlayButton
7879
isLoading={isLoading}
@@ -112,7 +113,7 @@ const PianoRoll: React.FC<PianoRollProps> = (props: PianoRollProps) => {
112113
viewableIndex={viewableIndex}
113114
/>
114115
</Pane>
115-
</React.Fragment>
116+
</Pane>
116117
);
117118
};
118119

src/components/sequencer/sequencer.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { useBoolean } from "utils/hooks/use-boolean";
1313
import { PlayButton } from "components/workstation/play-button";
1414
import { useToneAudio } from "utils/hooks/use-tone-audio";
1515
import { TrackRecord } from "models/track-record";
16+
import { toDataAttributes } from "utils/data-attribute-utils";
1617

1718
interface SequencerProps {
1819
files: List<FileRecord>;
@@ -60,17 +61,14 @@ const Sequencer: React.FC<SequencerProps> = (props: SequencerProps) => {
6061
isPlaying,
6162
files,
6263
tracks: List.of(track),
63-
trackSections: List.of(trackSection),
64+
trackSections: List.of(trackSection.merge({ step_count: stepCount })),
6465
trackSectionSteps,
6566
});
6667

67-
const sampleButtonText = `${selected.count()} ${pluralize(
68-
"Sample",
69-
selected.count()
70-
)}`;
68+
const sampleButtonText = pluralize("Sample", selected.count(), true);
7169

7270
return (
73-
<Pane>
71+
<Pane {...toDataAttributes({ stepCount })}>
7472
<Pane marginBottom={majorScale(1)}>
7573
<PlayButton
7674
isLoading={isLoading}

src/components/tracks/track-time/track-time.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { TrackTimeCard } from "components/tracks/track-time/track-time-card";
22
import { Pane } from "evergreen-ui";
33
import { range } from "lodash";
4+
import { toDataAttributes } from "utils/data-attribute-utils";
45
import { useToneControls } from "utils/hooks/use-tone-controls";
56

67
interface TrackTimeProps {
@@ -12,9 +13,11 @@ const TrackTime: React.FC<TrackTimeProps> = (props: TrackTimeProps) => {
1213
const { endIndex, startIndex } = useToneControls();
1314
return (
1415
<Pane
15-
data-end-index={endIndex}
16-
data-start-index={startIndex}
17-
data-step-count={stepCount}
16+
{...toDataAttributes({
17+
endIndex,
18+
startIndex,
19+
stepCount,
20+
})}
1821
display="flex"
1922
flexDirection="row">
2023
{range(0, stepCount).map((index: number) => (

src/constants/data-attributes.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { kebabCase, mapValues } from "lodash";
2+
import keyMirror from "keymirror";
3+
4+
const DataAttributes = mapValues(
5+
keyMirror({
6+
endIndex: null,
7+
index: null,
8+
startIndex: null,
9+
stepCount: null,
10+
}),
11+
(value: string) => `data-${kebabCase(value)}`
12+
);
13+
14+
export { DataAttributes };

src/scripts/codegen/constants/auditable-columns.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { keyMirror } from "../utils";
1+
import keyMirror from "keymirror";
22

33
const AuditableColumns = keyMirror({
44
created_on: null,

src/scripts/codegen/constants/variables.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { keyMirror } from "../utils";
1+
import keyMirror from "keymirror";
22

33
const Variables = keyMirror({
44
Auditable: null,

src/scripts/codegen/utils.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,6 @@ const getTablesEnumValue = (property: PropertySignature): string =>
8989
const getTableName = (property: PropertySignature): string =>
9090
pluralize(getInterfaceName(property), 2);
9191

92-
const keyMirror = <T extends Record<string, null>>(
93-
object: T
94-
): Record<keyof T, string> => {
95-
const keys = Object.keys(object);
96-
const outputObject: Record<string, string> = {};
97-
keys.forEach((key: string) => {
98-
outputObject[key] = key;
99-
});
100-
101-
return outputObject as Record<keyof T, string>;
102-
};
103-
10492
const removeExt = (filename: string) => upath.removeExt(filename, ".ts");
10593

10694
const snakeToTitleCase = (value: string) => {
@@ -148,7 +136,6 @@ export {
148136
getRecordSourceFile,
149137
getTablesEnumValue,
150138
getTableName,
151-
keyMirror,
152139
stripQuotes,
153140
toKebabCase,
154141
withExt,

src/utils/data-attribute-utils.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { DataAttributes } from "constants/data-attributes";
2+
import { Map } from "immutable";
3+
import { isEmpty, get } from "lodash";
4+
5+
const toDataAttributes = (
6+
values?: Partial<Record<keyof typeof DataAttributes, string | number>>
7+
): Record<string, unknown> => {
8+
let props: Map<string, unknown> = Map();
9+
10+
if (isEmpty(values)) {
11+
return props.toJS();
12+
}
13+
14+
Object.entries(values!).forEach(([key, value]) => {
15+
if (value == null) {
16+
return;
17+
}
18+
19+
// Get mapped data-attribute key
20+
props = props.set(get(DataAttributes, key), value);
21+
});
22+
23+
return props.toJS();
24+
};
25+
26+
export { toDataAttributes };

0 commit comments

Comments
 (0)