Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi segment audio #216

Closed
wants to merge 3 commits into from
Closed
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
22 changes: 0 additions & 22 deletions apps/desktop/src/routes/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,28 +119,6 @@ function Inner() {
)
);

const togglePlayback = async () => {
try {
if (playing()) {
await commands.stopPlayback(videoId);
setPlaying(false);
} else {
await commands.startPlayback(videoId);
setPlaying(true);
}
} catch (error) {
console.error("Error toggling playback:", error);
setPlaying(false);
}
};

createEventListener(document, "keydown", async (e: KeyboardEvent) => {
if (e.code === "Space" && e.target === document.body) {
e.preventDefault();
await togglePlayback();
}
});

return (
<div class="w-screen h-screen flex flex-col">
<Header />
Expand Down
53 changes: 19 additions & 34 deletions apps/desktop/src/routes/editor/Timeline.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import "~/styles/timeline.css";
import { createElementBounds } from "@solid-primitives/bounds";
import {
Accessor,
ComponentProps,
For,
Show,
Expand All @@ -12,24 +11,20 @@ import {
} from "solid-js";
import { createEventListenerMap } from "@solid-primitives/event-listener";
import { cx } from "cva";
import { createStore, produce } from "solid-js/store";
import { produce } from "solid-js/store";
import { mergeRefs } from "@solid-primitives/refs";
import { createContextProvider } from "@solid-primitives/context";
import { createMemo } from "solid-js";

import { commands, TimelineSegment } from "~/utils/tauri";
import { useEditorContext } from "./context";
import {
TimelineContextProvider,
TrackContextProvider,
useEditorContext,
useTimelineContext,
useTrackContext,
} from "./context";
import { formatTime } from "./utils";

const [TimelineContextProvider, useTimelineContext] = createContextProvider(
(props: { duration: number }) => {
return {
duration: () => props.duration,
};
},
null!
);

export function Timeline() {
const {
project,
Expand Down Expand Up @@ -289,6 +284,12 @@ export function Timeline() {
segment.recordingSegment ?? 0
].display.duration;

console.log(
editorInstance.recordings.segments[
segment.recordingSegment ?? 0
]
);

const availableTimelineDuration =
editorInstance.recordingDuration -
segments().reduce(
Expand Down Expand Up @@ -319,7 +320,11 @@ export function Timeline() {
i(),
"end",
Math.max(
Math.min(newEnd, segment.start + maxDuration),
Math.min(
newEnd,
maxSegmentDuration,
availableTimelineDuration
),
segment.start + 1
)
);
Expand Down Expand Up @@ -630,26 +635,6 @@ export function Timeline() {
);
}

const [TrackContextProvider, useTrackContext] = createContextProvider(
(props: {
ref: Accessor<Element | undefined>;
isFreeForm: Accessor<boolean>;
}) => {
const [trackState, setTrackState] = createStore({
draggingHandle: false,
});
const bounds = createElementBounds(() => props.ref());

return {
trackBounds: bounds,
isFreeForm: () => props.isFreeForm(),
trackState,
setTrackState,
};
},
null!
);

function TrackRoot(props: ComponentProps<"div"> & { isFreeForm: boolean }) {
const [ref, setRef] = createSignal<HTMLDivElement>();

Expand Down
30 changes: 29 additions & 1 deletion apps/desktop/src/routes/editor/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { trackStore } from "@solid-primitives/deep";
import { createEventListener } from "@solid-primitives/event-listener";
import { createUndoHistory } from "@solid-primitives/history";
import { debounce } from "@solid-primitives/scheduled";
import { createEffect, createSignal, on } from "solid-js";
import { Accessor, createEffect, createSignal, on } from "solid-js";
import { createStore, reconcile, unwrap } from "solid-js/store";

import type { PresetsStore } from "../../store";
Expand All @@ -15,6 +15,7 @@ import {
} from "~/utils/tauri";
import { useEditorInstanceContext } from "./editorInstanceContext";
import { DEFAULT_PROJECT_CONFIG } from "./projectConfig";
import { createElementBounds } from "@solid-primitives/bounds";

export type CurrentDialog =
| { type: "createPreset" }
Expand Down Expand Up @@ -148,3 +149,30 @@ type Static<T = unknown> =
[K in number | string]: T;
}
| T[];

export const [TimelineContextProvider, useTimelineContext] =
createContextProvider((props: { duration: number }) => {
return {
duration: () => props.duration,
};
}, null!);

export const [TrackContextProvider, useTrackContext] = createContextProvider(
(props: {
ref: Accessor<Element | undefined>;
isFreeForm: Accessor<boolean>;
}) => {
const [trackState, setTrackState] = createStore({
draggingHandle: false,
});
const bounds = createElementBounds(() => props.ref());

return {
trackBounds: bounds,
isFreeForm: () => props.isFreeForm(),
trackState,
setTrackState,
};
},
null!
);
2 changes: 1 addition & 1 deletion crates/flags/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ pub const FLAGS: Flags = Flags {
record_mouse: false, // cfg!(debug_assertions),
split: false, // cfg!(debug_assertions),
pause_resume: false, // cfg!(debug_assertions),
zoom: false, // false, // false, // cfg!(debug_assertions),
zoom: false, // cfg!(debug_assertions),
custom_s3: true,
};
1 change: 1 addition & 0 deletions crates/media/src/feeds/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ impl AudioFrameBuffer {

let buffer = &self.data[self.cursor.0].buffer;
if self.cursor.1 >= buffer.len() {
self.elapsed_samples += samples;
return None;
}

Expand Down
2 changes: 1 addition & 1 deletion crates/recording/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub mod actor;
mod cursor;
pub mod segmented_actor;

pub use actor::{spawn_recording_actor, ActorHandle, CompletedRecording, RecordingError};
pub use segmented_actor::{spawn_recording_actor, ActorHandle, CompletedRecording, RecordingError};

use cap_media::sources::*;
use serde::{Deserialize, Serialize};
Expand Down
Loading