Skip to content

Commit

Permalink
feat: LEAP-1900: Add setting to disable autoplaying of new audio regions
Browse files Browse the repository at this point in the history
  • Loading branch information
hlomzik committed Mar 5, 2025
1 parent 0d09166 commit 71b0433
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ export const ConfigControl: FC<ConfigControlProps> = ({
label="Loop Regions"
/>
</Elem>
<Elem name="toggle">
<Toggle
checked={settings?.autoPlayNewSegments}
onChange={(e) => changeSetting?.("autoPlayNewSegments", e.target.checked)}
label="Auto-play New Regions"
/>
</Elem>
{renderLayerToggles()}
</Elem>
);
Expand Down
1 change: 1 addition & 0 deletions web/libs/editor/src/components/Timeline/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export type TimelineSettings = {
stepSize?: TimelineStepFunction;
leftOffset?: number;
loopRegion?: boolean;
autoPlayNewSegments?: boolean;
};

export type TimelineStepFunction = (
Expand Down
4 changes: 2 additions & 2 deletions web/libs/editor/src/lib/AudioUltra/Regions/Regions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ export class Regions {

const addRegion = () => {
const { container, zoomedWidth, fullWidth } = this.visualizer;
const { autoPlayNewSegments, duration } = this.waveform;
const { settings: { autoPlayNewSegments }, duration } = this.waveform;
const scrollLeft = this.visualizer.getScrollLeftPx();

startX = clamp(getCursorPositionX(e, container) + scrollLeft, 0, fullWidth);
Expand Down Expand Up @@ -352,7 +352,7 @@ export class Regions {
};

const handleMouseUp = () => {
const { player, autoPlayNewSegments } = this.waveform;
const { player, settings: { autoPlayNewSegments } } = this.waveform;

document.removeEventListener("mousemove", handleMouseMove);
document.removeEventListener("mouseup", handleMouseUp);
Expand Down
5 changes: 0 additions & 5 deletions web/libs/editor/src/lib/AudioUltra/Waveform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ export interface WaveformOptions {

padding?: Padding;

autoPlayNewSegments?: boolean;

// Cursor options
cursor?: CursorOptions;

Expand Down Expand Up @@ -202,7 +200,6 @@ export class Waveform extends Events<WaveformEventTypes> {
regions!: Regions;
loaded = false;
renderedChannels = false;
autoPlayNewSegments = false;
// for now that's just an object to store setting and access them when needed;
// but if we need to react on changes we can convert it into getter/setter.
settings: TimelineSettings = {};
Expand Down Expand Up @@ -258,8 +255,6 @@ export class Waveform extends Events<WaveformEventTypes> {
this.visualizer,
);

this.autoPlayNewSegments = this.params.autoPlayNewSegments ?? this.autoPlayNewSegments;

this.player = this.params.playerType === "html5" ? new Html5Player(this) : new WebAudioPlayer(this);

this.initEvents();
Expand Down
2 changes: 1 addition & 1 deletion web/libs/editor/src/tags/object/AudioUltra/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ const AudioUltraView: FC<AudioUltraProps> = ({ item }) => {
backgroundCompute: true,
denoize: true,
},
autoPlayNewSegments: true,
onFrameChanged: (frameState) => {
item.setWFFrame(frameState);
},
Expand Down Expand Up @@ -211,6 +210,7 @@ const AudioUltraWithSettings: FC<AudioUltraProps> = ({ item }) => {
const [settings, setSettings] = useState({
playpauseHotkey: "audio:playpause",
loopRegion: false,
autoPlayNewSegments: true,
});
const changeSetting = useCallback((key: string, value: any) => {
setSettings((prev) => ({ ...prev, [key]: value }));
Expand Down

0 comments on commit 71b0433

Please sign in to comment.