Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

feat(editor): always show the audio lane + an "Add audio" shortcut (M)

Benjamin Freemanf330d33263fe
diff --git a/src/components/ai-edition/NewEditorShell.tsx b/src/components/ai-edition/NewEditorShell.tsx
index 81b9ab7d7..4c8120beb 100644
--- a/src/components/ai-edition/NewEditorShell.tsx
+++ b/src/components/ai-edition/NewEditorShell.tsx
@@ -1048,6 +1048,13 @@ export function NewEditorShell() {
void tl.addAnnotation(newRegionDurationSec());
return;
}
+ // Unlike its neighbours this opens a file picker rather than dropping a region at
+ // the playhead — there is nothing to size, so it takes no duration (issue #350).
+ if (matchesShortcut(e, shortcuts.addAudio, isMac)) {
+ e.preventDefault();
+ void tl.addAudio();
+ return;
+ }
if (matchesShortcut(e, shortcuts.addSpeed, isMac)) {
e.preventDefault();
void tl.addSpeed(newRegionDurationSec());
diff --git a/src/components/ai-edition/v4/V4Timeline.tsx b/src/components/ai-edition/v4/V4Timeline.tsx
index a03368963..445c0ac51 100644
--- a/src/components/ai-edition/v4/V4Timeline.tsx
+++ b/src/components/ai-edition/v4/V4Timeline.tsx
@@ -485,24 +485,6 @@ export function V4Timeline({
shiftPx: number;
} | null>(null);
const { settings, set: setSettings } = useEditorSettings();
- const importAudioAsset = useProjectStore((s) => s.importAudioAsset);
-
- // Import an audio file straight onto the timeline (issue #350). Audio is a
- // timeline overlay like an annotation, not a media-tab clip, so it is added
- // from here: pick a file, then `importAudioAsset` adds a kind:"audio" asset and
- // places a track at the playhead in one step.
- const handleAddAudio = useCallback(async () => {
- const picker = await window.electronAPI?.openAudioFilePicker?.();
- if (!picker?.success || !picker.path) return;
- try {
- const label = picker.name || picker.path.split(/[\\/]/).pop() || "Audio";
- await importAudioAsset(picker.path, label);
- } catch (err) {
- toast.error(ts("audioTrack.importFailed"), {
- description: err instanceof Error ? err.message : String(err),
- });
- }
- }, [importAudioAsset, ts]);
const [autoEnhanceOpen, setAutoEnhanceOpen] = useState(false);
const [autoBusy, setAutoBusy] = useState(false);
@@ -1568,7 +1550,7 @@ export function V4Timeline({
className={styles.tlToolBtn}
title={ts("audioTrack.add")}
aria-label={ts("audioTrack.add")}
- onClick={() => void handleAddAudio()}
+ onClick={() => void tl.addAudio()}
>
<Music size={15} />
</button>
@@ -1709,12 +1691,20 @@ export function V4Timeline({
hasAnyCamera ? t("hints.pressCameraFullscreen") : ts("layout.noWebcam"),
)}
</div>
- {/* Imported audio tracks (issue #350). Only shown once a track exists —
- audio arrives via the media panel's "Import audio", not a keystroke,
- so an empty lane would advertise nothing. */}
- {tl.audioTracks.length > 0 ? (
- <div className={`${styles.tlLane} ${styles.tlLaneAudio}`}>
- {tl.audioTracks.map((track) => {
+ {/* Imported audio tracks (issue #350). Always shown, like every other
+ lane — "Add audio" is a toolbar peer of the region tools now (and
+ has a keyboard shortcut), so an empty lane advertises the shortcut
+ that fills it rather than hiding until the first import. */}
+ <div className={`${styles.tlLane} ${styles.tlLaneAudio}`}>
+ {tl.audioTracks.length === 0 ? (
+ <span
+ className={styles.laneEmpty}
+ style={{ left: `${nav.start * 100}%`, width: `${navSpan * 100}%` }}
+ >
+ {t("hints.pressAudio")}
+ </span>
+ ) : (
+ tl.audioTracks.map((track) => {
const asset = tl.assets.find((a) => a.id === track.assetId);
const duration = asset?.durationSec ?? track.durationSec;
// While this track is being dragged, lay it out from the live
@@ -1738,9 +1728,9 @@ export function V4Timeline({
label={track.label || asset?.label || ts("audioTrack.defaultLabel")}
/>
);
- })}
- </div>
- ) : null}
+ })
+ )}
+ </div>
</>
) : null}
diff --git a/src/i18n/locales/ar/shortcuts.json b/src/i18n/locales/ar/shortcuts.json
index d8c063784..f9a834289 100644
--- a/src/i18n/locales/ar/shortcuts.json
+++ b/src/i18n/locales/ar/shortcuts.json
@@ -20,6 +20,7 @@
"addTrim": "إضافة قص",
"addSpeed": "إضافة سرعة",
"addAnnotation": "إضافة شرح",
+ "addAudio": "إضافة صوت",
"addKeyframe": "إضافة إطار رئيسي",
"addCameraFullscreen": "إضافة كاميرا كاملة الشاشة",
"deleteSelected": "حذف المحدد",
diff --git a/src/i18n/locales/ar/timeline.json b/src/i18n/locales/ar/timeline.json
index 4412a0a0b..598e9e625 100644
--- a/src/i18n/locales/ar/timeline.json
+++ b/src/i18n/locales/ar/timeline.json
@@ -15,6 +15,7 @@
"pressZoom": "اضغط Z لإضافة تكبير",
"pressTrim": "اضغط T لإضافة قص",
"pressAnnotation": "اضغط A لإضافة شرح",
+ "pressAudio": "اضغط M لإضافة صوت",
"pressSpeed": "اضغط S لإضافة سرعة",
"pressCameraFullscreen": "اضغط C لإضافة مقطع كاميرا كاملة الشاشة"
},
diff --git a/src/i18n/locales/en/shortcuts.json b/src/i18n/locales/en/shortcuts.json
index 081aceada..ab4e9e45d 100644
--- a/src/i18n/locales/en/shortcuts.json
+++ b/src/i18n/locales/en/shortcuts.json
@@ -20,6 +20,7 @@
"addTrim": "Add Trim",
"addSpeed": "Add Speed",
"addAnnotation": "Add Annotation",
+ "addAudio": "Add Audio",
"addKeyframe": "Add Keyframe",
"addCameraFullscreen": "Add Full Camera",
"deleteSelected": "Delete Selected",
diff --git a/src/i18n/locales/en/timeline.json b/src/i18n/locales/en/timeline.json
index c41966115..d5e11e7e2 100644
--- a/src/i18n/locales/en/timeline.json
+++ b/src/i18n/locales/en/timeline.json
@@ -15,6 +15,7 @@
"pressZoom": "Press Z to add zoom",
"pressTrim": "Press T to add trim",
"pressAnnotation": "Press A to add annotation",
+ "pressAudio": "Press M to add audio",
"pressSpeed": "Press S to add speed",
"pressCameraFullscreen": "Press C to add a Full Camera segment"
},
diff --git a/src/i18n/locales/es/shortcuts.json b/src/i18n/locales/es/shortcuts.json
index 970c52306..7753389d2 100644
--- a/src/i18n/locales/es/shortcuts.json
+++ b/src/i18n/locales/es/shortcuts.json
@@ -20,6 +20,7 @@
"addTrim": "Agregar recorte",
"addSpeed": "Agregar velocidad",
"addAnnotation": "Agregar anotación",
+ "addAudio": "Añadir audio",
"addKeyframe": "Agregar fotograma clave",
"addCameraFullscreen": "Agregar cámara a pantalla completa",
"deleteSelected": "Eliminar seleccionado",
diff --git a/src/i18n/locales/es/timeline.json b/src/i18n/locales/es/timeline.json
index 989289e00..2c2e64f4f 100644
--- a/src/i18n/locales/es/timeline.json
+++ b/src/i18n/locales/es/timeline.json
@@ -15,6 +15,7 @@
"pressZoom": "Presiona Z para agregar zoom",
"pressTrim": "Presiona T para agregar recorte",
"pressAnnotation": "Presiona A para agregar anotación",
+ "pressAudio": "Pulsa M para añadir audio",
"pressSpeed": "Presiona S para agregar velocidad",
"pressCameraFullscreen": "Presiona C para agregar un segmento de cámara a pantalla completa"
},
diff --git a/src/i18n/locales/fr/shortcuts.json b/src/i18n/locales/fr/shortcuts.json
index 659ef13b8..93ff5af11 100644
--- a/src/i18n/locales/fr/shortcuts.json
+++ b/src/i18n/locales/fr/shortcuts.json
@@ -20,6 +20,7 @@
"addTrim": "Ajouter une coupe",
"addSpeed": "Ajouter une vitesse",
"addAnnotation": "Ajouter une annotation",
+ "addAudio": "Ajouter un audio",
"addKeyframe": "Ajouter une image-clé",
"addCameraFullscreen": "Ajouter une caméra en plein écran",
"deleteSelected": "Supprimer la sélection",
diff --git a/src/i18n/locales/fr/timeline.json b/src/i18n/locales/fr/timeline.json
index a35b8858a..aef72afba 100644
--- a/src/i18n/locales/fr/timeline.json
+++ b/src/i18n/locales/fr/timeline.json
@@ -15,6 +15,7 @@
"pressZoom": "Appuyez sur Z pour ajouter un zoom",
"pressTrim": "Appuyez sur T pour ajouter une coupe",
"pressAnnotation": "Appuyez sur A pour ajouter une annotation",
+ "pressAudio": "Appuyez sur M pour ajouter un audio",
"pressSpeed": "Appuyez sur S pour ajouter une vitesse",
"pressCameraFullscreen": "Appuyez sur C pour ajouter un segment Caméra plein écran"
},
diff --git a/src/i18n/locales/it/shortcuts.json b/src/i18n/locales/it/shortcuts.json
index 6a2da2208..5e7eeee42 100644
--- a/src/i18n/locales/it/shortcuts.json
+++ b/src/i18n/locales/it/shortcuts.json
@@ -20,6 +20,7 @@
"addTrim": "Aggiungi taglio",
"addSpeed": "Aggiungi velocità",
"addAnnotation": "Aggiungi annotazione",
+ "addAudio": "Aggiungi audio",
"addKeyframe": "Aggiungi fotogramma chiave",
"addCameraFullscreen": "Aggiungi Camera a schermo intero",
"deleteSelected": "Elimina selezionato",
diff --git a/src/i18n/locales/it/timeline.json b/src/i18n/locales/it/timeline.json
index 09bb116ee..1fe62947d 100644
--- a/src/i18n/locales/it/timeline.json
+++ b/src/i18n/locales/it/timeline.json
@@ -15,6 +15,7 @@
"pressZoom": "Premi Z per aggiungere zoom",
"pressTrim": "Premi T per aggiungere taglio",
"pressAnnotation": "Premi A per aggiungere annotazione",
+ "pressAudio": "Premi M per aggiungere audio",
"pressSpeed": "Premi S per aggiungere velocità",
"pressCameraFullscreen": "Premi C per aggiungere un segmento Camera a schermo intero"
},
diff --git a/src/i18n/locales/ja-JP/shortcuts.json b/src/i18n/locales/ja-JP/shortcuts.json
index 173355c66..1d994fb68 100644
--- a/src/i18n/locales/ja-JP/shortcuts.json
+++ b/src/i18n/locales/ja-JP/shortcuts.json
@@ -20,6 +20,7 @@
"addTrim": "トリムを追加",
"addSpeed": "速度を追加",
"addAnnotation": "注釈を追加",
+ "addAudio": "音声を追加",
"addKeyframe": "キーフレームを追加",
"addCameraFullscreen": "フルスクリーンカメラを追加",
"deleteSelected": "選択を削除",
diff --git a/src/i18n/locales/ja-JP/timeline.json b/src/i18n/locales/ja-JP/timeline.json
index 68911ba91..7a5f983d8 100644
--- a/src/i18n/locales/ja-JP/timeline.json
+++ b/src/i18n/locales/ja-JP/timeline.json
@@ -15,6 +15,7 @@
"pressZoom": "Zキーを押してズームを追加",
"pressTrim": "Tキーを押してトリムを追加",
"pressAnnotation": "Aキーを押して注釈を追加",
+ "pressAudio": "Mキーを押して音声を追加",
"pressSpeed": "Sキーを押して再生速度を追加",
"pressCameraFullscreen": "Cキーを押してフルスクリーンカメラのセグメントを追加"
},
diff --git a/src/i18n/locales/ko-KR/shortcuts.json b/src/i18n/locales/ko-KR/shortcuts.json
index 00e8f689d..82ec503ed 100644
--- a/src/i18n/locales/ko-KR/shortcuts.json
+++ b/src/i18n/locales/ko-KR/shortcuts.json
@@ -20,6 +20,7 @@
"addTrim": "트림 추가",
"addSpeed": "속도 추가",
"addAnnotation": "주석 추가",
+ "addAudio": "오디오 추가",
"addKeyframe": "키프레임 추가",
"addCameraFullscreen": "전체 화면 카메라 추가",
"deleteSelected": "선택 항목 삭제",
diff --git a/src/i18n/locales/ko-KR/timeline.json b/src/i18n/locales/ko-KR/timeline.json
index 8a100ee6d..36daae802 100644
--- a/src/i18n/locales/ko-KR/timeline.json
+++ b/src/i18n/locales/ko-KR/timeline.json
@@ -15,6 +15,7 @@
"pressZoom": "Z를 눌러 줌 추가",
"pressTrim": "T를 눌러 트림 추가",
"pressAnnotation": "A를 눌러 주석 추가",
+ "pressAudio": "M을 눌러 오디오 추가",
"pressSpeed": "S를 눌러 속도 추가",
"pressCameraFullscreen": "C를 눌러 전체 화면 카메라 구간을 추가하세요"
},
diff --git a/src/i18n/locales/pt-BR/shortcuts.json b/src/i18n/locales/pt-BR/shortcuts.json
index a21fe7bed..ea7787c1d 100644
--- a/src/i18n/locales/pt-BR/shortcuts.json
+++ b/src/i18n/locales/pt-BR/shortcuts.json
@@ -20,6 +20,7 @@
"addTrim": "Adicionar Recorte",
"addSpeed": "Adicionar Velocidade",
"addAnnotation": "Adicionar Anotação",
+ "addAudio": "Adicionar áudio",
"addKeyframe": "Adicionar Quadro-chave",
"addCameraFullscreen": "Adicionar Câmera em Tela Cheia",
"deleteSelected": "Excluir Selecionado",
diff --git a/src/i18n/locales/pt-BR/timeline.json b/src/i18n/locales/pt-BR/timeline.json
index 5359feba9..748ac7486 100644
--- a/src/i18n/locales/pt-BR/timeline.json
+++ b/src/i18n/locales/pt-BR/timeline.json
@@ -15,6 +15,7 @@
"pressZoom": "Pressione Z para adicionar zoom",
"pressTrim": "Pressione T para adicionar recorte",
"pressAnnotation": "Pressione A para adicionar anotação",
+ "pressAudio": "Pressione M para adicionar áudio",
"pressSpeed": "Pressione S para adicionar velocidade",
"pressCameraFullscreen": "Pressione C para adicionar um segmento de Câmera em Tela Cheia"
},
diff --git a/src/i18n/locales/ru/shortcuts.json b/src/i18n/locales/ru/shortcuts.json
index dabb06801..ce5747ea4 100644
--- a/src/i18n/locales/ru/shortcuts.json
+++ b/src/i18n/locales/ru/shortcuts.json
@@ -20,6 +20,7 @@
"addTrim": "Добавить обрезку",
"addSpeed": "Изменить скорость",
"addAnnotation": "Добавить аннотацию",
+ "addAudio": "Добавить аудио",
"addKeyframe": "Добавить ключевой кадр",
"addCameraFullscreen": "Добавить камеру на весь экран",
"deleteSelected": "Удалить выбранное",
diff --git a/src/i18n/locales/ru/timeline.json b/src/i18n/locales/ru/timeline.json
index 387086953..8ee40a66c 100644
--- a/src/i18n/locales/ru/timeline.json
+++ b/src/i18n/locales/ru/timeline.json
@@ -15,6 +15,7 @@
"pressZoom": "Нажмите Z для добавления масштабирования",
"pressTrim": "Нажмите T для добавления обрезки",
"pressAnnotation": "Нажмите A для добавления аннотации",
+ "pressAudio": "Нажмите M, чтобы добавить аудио",
"pressSpeed": "Нажмите S для изменения скорости",
"pressCameraFullscreen": "Нажмите C, чтобы добавить сегмент камеры на весь экран"
},
diff --git a/src/i18n/locales/tr/shortcuts.json b/src/i18n/locales/tr/shortcuts.json
index 6b1db110d..b670fdbc4 100644
--- a/src/i18n/locales/tr/shortcuts.json
+++ b/src/i18n/locales/tr/shortcuts.json
@@ -20,6 +20,7 @@
"addTrim": "Kırpma Ekle",
"addSpeed": "Hız Ekle",
"addAnnotation": "Açıklama Ekle",
+ "addAudio": "Ses ekle",
"addKeyframe": "Anahtar Kare Ekle",
"addCameraFullscreen": "Tam Ekran Kamera Ekle",
"deleteSelected": "Seçileni Sil",
diff --git a/src/i18n/locales/tr/timeline.json b/src/i18n/locales/tr/timeline.json
index d5a531f3e..2a6481612 100644
--- a/src/i18n/locales/tr/timeline.json
+++ b/src/i18n/locales/tr/timeline.json
@@ -15,6 +15,7 @@
"pressZoom": "Yakınlaştırma eklemek için Z tuşuna basın",
"pressTrim": "Kırpma eklemek için T tuşuna basın",
"pressAnnotation": "Açıklama eklemek için A tuşuna basın",
+ "pressAudio": "Ses eklemek için M'ye basın",
"pressSpeed": "Hız eklemek için S tuşuna basın",
"pressCameraFullscreen": "Tam Ekran Kamera bölümü eklemek için C tuşuna basın"
},
diff --git a/src/i18n/locales/vi/shortcuts.json b/src/i18n/locales/vi/shortcuts.json
index cf49f2526..6ffb15e98 100644
--- a/src/i18n/locales/vi/shortcuts.json
+++ b/src/i18n/locales/vi/shortcuts.json
@@ -20,6 +20,7 @@
"addTrim": "Thêm Cắt",
"addSpeed": "Thêm Tốc độ",
"addAnnotation": "Thêm Chú thích",
+ "addAudio": "Thêm âm thanh",
"addKeyframe": "Thêm Khung hình chính",
"addCameraFullscreen": "Thêm Camera Toàn màn hình",
"deleteSelected": "Xóa mục đã chọn",
diff --git a/src/i18n/locales/vi/timeline.json b/src/i18n/locales/vi/timeline.json
index 1d963e585..25f55bd19 100644
--- a/src/i18n/locales/vi/timeline.json
+++ b/src/i18n/locales/vi/timeline.json
@@ -15,6 +15,7 @@
"pressZoom": "Nhấn Z để thêm thu phóng",
"pressTrim": "Nhấn T để thêm cắt",
"pressAnnotation": "Nhấn A để thêm chú thích",
+ "pressAudio": "Nhấn M để thêm âm thanh",
"pressSpeed": "Nhấn S để thêm tốc độ",
"pressCameraFullscreen": "Nhấn C để thêm một đoạn Camera Toàn màn hình"
},
diff --git a/src/i18n/locales/zh-CN/shortcuts.json b/src/i18n/locales/zh-CN/shortcuts.json
index 95ec1c07e..da2d95a5d 100644
--- a/src/i18n/locales/zh-CN/shortcuts.json
+++ b/src/i18n/locales/zh-CN/shortcuts.json
@@ -20,6 +20,7 @@
"addTrim": "添加剪辑",
"addSpeed": "添加速度",
"addAnnotation": "添加标注",
+ "addAudio": "添加音频",
"addKeyframe": "添加关键帧",
"addCameraFullscreen": "添加全屏摄像头",
"deleteSelected": "删除所选",
diff --git a/src/i18n/locales/zh-CN/timeline.json b/src/i18n/locales/zh-CN/timeline.json
index 1451e6d31..9af9c1f96 100644
--- a/src/i18n/locales/zh-CN/timeline.json
+++ b/src/i18n/locales/zh-CN/timeline.json
@@ -15,6 +15,7 @@
"pressZoom": "按 Z 添加缩放",
"pressTrim": "按 T 添加剪辑",
"pressAnnotation": "按 A 添加标注",
+ "pressAudio": "按 M 添加音频",
"pressSpeed": "按 S 添加速度",
"pressCameraFullscreen": "按 C 添加一个全屏摄像头片段"
},
diff --git a/src/i18n/locales/zh-TW/shortcuts.json b/src/i18n/locales/zh-TW/shortcuts.json
index fd8c6434b..4819bee87 100644
--- a/src/i18n/locales/zh-TW/shortcuts.json
+++ b/src/i18n/locales/zh-TW/shortcuts.json
@@ -20,6 +20,7 @@
"addTrim": "新增剪輯",
"addSpeed": "新增速度",
"addAnnotation": "新增標註",
+ "addAudio": "新增音訊",
"addKeyframe": "新增關鍵影格",
"addCameraFullscreen": "新增全螢幕攝影機",
"deleteSelected": "刪除所選",
diff --git a/src/i18n/locales/zh-TW/timeline.json b/src/i18n/locales/zh-TW/timeline.json
index 7f4ba9874..7a632893e 100644
--- a/src/i18n/locales/zh-TW/timeline.json
+++ b/src/i18n/locales/zh-TW/timeline.json
@@ -15,6 +15,7 @@
"pressZoom": "按 Z 新增縮放",
"pressTrim": "按 T 新增剪輯",
"pressAnnotation": "按 A 新增標註",
+ "pressAudio": "按 M 新增音訊",
"pressSpeed": "按 S 新增速度",
"pressCameraFullscreen": "按 C 新增一個全螢幕攝影機片段"
},
diff --git a/src/lib/ai-edition/store/useTimeline.test.ts b/src/lib/ai-edition/store/useTimeline.test.ts
index 68bf29a97..0b0cb47cd 100644
--- a/src/lib/ai-edition/store/useTimeline.test.ts
+++ b/src/lib/ai-edition/store/useTimeline.test.ts
@@ -1407,6 +1407,34 @@ describe("useTimeline audio tracks", () => {
expect(useProjectStore.getState().document?.audioTracks).toEqual([]);
});
+ // #350: the toolbar button and the `M` shortcut both call `tl.addAudio`, which opens
+ // the OS file picker and hands the result to `importAudioAsset`. Spy on the store's
+ // import so these assert the wiring (picker → import), not the import itself.
+ it("addAudio imports the picked file, and is a no-op when the picker is cancelled", async () => {
+ const importSpy = vi.fn().mockResolvedValue(null);
+ useProjectStore.setState({ importAudioAsset: importSpy });
+ const pickerMock = vi.fn();
+ Object.defineProperty(window, "electronAPI", {
+ configurable: true,
+ value: { openAudioFilePicker: pickerMock },
+ });
+ const { result } = renderTimeline();
+
+ // Cancelled picker → nothing imported.
+ pickerMock.mockResolvedValueOnce({ success: false });
+ await act(async () => {
+ await result.current.addAudio();
+ });
+ expect(importSpy).not.toHaveBeenCalled();
+
+ // Picked a file → imported with its path and display name.
+ pickerMock.mockResolvedValueOnce({ success: true, path: "/tmp/bgm.mp3", name: "bgm.mp3" });
+ await act(async () => {
+ await result.current.addAudio();
+ });
+ expect(importSpy).toHaveBeenCalledWith("/tmp/bgm.mp3", "bgm.mp3");
+ });
+
// #350 regression: a failed import-time probe leaves durationSec at 0, which
// makes the playback window zero-length. The on-load backfill re-probes and
// stamps the real duration onto the asset AND the track, so it can play again.
diff --git a/src/lib/ai-edition/store/useTimeline.ts b/src/lib/ai-edition/store/useTimeline.ts
index df761bfed..e107f9b87 100644
--- a/src/lib/ai-edition/store/useTimeline.ts
+++ b/src/lib/ai-edition/store/useTimeline.ts
@@ -4,6 +4,7 @@
// (a reasonable default for the user to then resize).
import { useCallback, useEffect, useRef, useState } from "react";
+import { toast } from "sonner";
import { toFileUrl } from "@/components/video-editor/projectPersistence";
import type { AnnotationRegion, AnnotationType } from "@/components/video-editor/types";
import { useScopedT } from "@/contexts/I18nContext";
@@ -118,6 +119,7 @@ export function useTimeline() {
const selectedAudioTrackId = useProjectStore((s) => s.selectedAudioTrackId);
const setSelectedAudioTrackId = useProjectStore((s) => s.setSelectedAudioTrackId);
const storeAddAudioTrack = useProjectStore((s) => s.addAudioTrack);
+ const importAudioAsset = useProjectStore((s) => s.importAudioAsset);
// Pre-drag snapshots for the two optimistic paths (zoom focus, annotations), so a
// failed commit can put the document back instead of leaving an edit on screen that
// was never written.
@@ -1276,6 +1278,23 @@ export function useTimeline() {
[storeAddAudioTrack],
);
+ // Import an audio file and drop it on the timeline (issue #350). Lives here — not in
+ // the timeline toolbar — so the toolbar button and the keyboard shortcut (both call
+ // through `tl`) share one path. Opens a file picker, so unlike the region adds it takes
+ // no playhead duration; `importAudioAsset` places the track at the current playhead.
+ const addAudio = useCallback(async () => {
+ const picker = await window.electronAPI?.openAudioFilePicker?.();
+ if (!picker?.success || !picker.path) return;
+ try {
+ const label = picker.name || picker.path.split(/[\\/]/).pop() || "Audio";
+ await importAudioAsset(picker.path, label);
+ } catch (err) {
+ toast.error(ts("audioTrack.importFailed"), {
+ description: err instanceof Error ? err.message : String(err),
+ });
+ }
+ }, [importAudioAsset, ts]);
+
const removeAudioTrack = useCallback(
async (trackId: string) => {
if (!document) return;
@@ -1335,6 +1354,7 @@ export function useTimeline() {
removeRegion,
removeRegions,
addAudioTrack,
+ addAudio,
removeAudioTrack,
placeAudioTrack,
setAudioTrackGain,
diff --git a/src/lib/shortcuts.ts b/src/lib/shortcuts.ts
index 0487b91c7..5617a1a3e 100644
--- a/src/lib/shortcuts.ts
+++ b/src/lib/shortcuts.ts
@@ -5,6 +5,7 @@ export const SHORTCUT_ACTIONS = [
"addSpeed",
"addCameraFullscreen",
"addAnnotation",
+ "addAudio",
"deleteSelected",
"playPause",
"copySelected",
@@ -113,6 +114,7 @@ export const DEFAULT_SHORTCUTS: ShortcutsConfig = {
addSpeed: { key: "s" },
addCameraFullscreen: { key: "c" },
addAnnotation: { key: "a" },
+ addAudio: { key: "m" },
deleteSelected: { key: "d", ctrl: true },
playPause: { key: " " },
copySelected: { key: "c", ctrl: true },
@@ -126,6 +128,7 @@ export const SHORTCUT_LABELS: Record<ShortcutAction, string> = {
addSpeed: "Add Speed",
addCameraFullscreen: "Add Full Camera",
addAnnotation: "Add Annotation",
+ addAudio: "Add Audio",
deleteSelected: "Delete Selected",
playPause: "Play / Pause",
copySelected: "Copy Selected",