loukai-app 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +558 -0
- package/bin/loukai.js +32 -0
- package/package.json +243 -0
- package/src/main/appState.js +250 -0
- package/src/main/audioEngine.js +478 -0
- package/src/main/creator/conversionService.js +503 -0
- package/src/main/creator/downloadManager.js +1128 -0
- package/src/main/creator/ffmpegService.js +487 -0
- package/src/main/creator/installLogger.js +51 -0
- package/src/main/creator/keyDetection.js +212 -0
- package/src/main/creator/llmService.js +370 -0
- package/src/main/creator/lrclibService.js +340 -0
- package/src/main/creator/python/crepe_runner.py +189 -0
- package/src/main/creator/python/demucs_runner.py +158 -0
- package/src/main/creator/python/whisper_runner.py +172 -0
- package/src/main/creator/pythonRunner.js +268 -0
- package/src/main/creator/stemBuilder.js +491 -0
- package/src/main/creator/systemChecker.js +474 -0
- package/src/main/handlers/appHandlers.js +45 -0
- package/src/main/handlers/audioHandlers.js +33 -0
- package/src/main/handlers/autotuneHandlers.js +28 -0
- package/src/main/handlers/canvasHandlers.js +84 -0
- package/src/main/handlers/creatorHandlers.js +159 -0
- package/src/main/handlers/editorHandlers.js +98 -0
- package/src/main/handlers/effectsHandlers.js +100 -0
- package/src/main/handlers/fileHandlers.js +45 -0
- package/src/main/handlers/index.js +78 -0
- package/src/main/handlers/libraryHandlers.js +96 -0
- package/src/main/handlers/mixerHandlers.js +64 -0
- package/src/main/handlers/playerHandlers.js +39 -0
- package/src/main/handlers/preferencesHandlers.js +46 -0
- package/src/main/handlers/queueHandlers.js +81 -0
- package/src/main/handlers/rendererHandlers.js +63 -0
- package/src/main/handlers/settingsHandlers.js +42 -0
- package/src/main/handlers/webServerHandlers.js +105 -0
- package/src/main/main.js +2351 -0
- package/src/main/preload.js +252 -0
- package/src/main/settingsManager.js +139 -0
- package/src/main/statePersistence.js +193 -0
- package/src/main/utils/pathValidator.js +112 -0
- package/src/main/webServer.js +2535 -0
- package/src/native/autotune.js +417 -0
- package/src/renderer/adapters/ElectronBridge.js +677 -0
- package/src/renderer/canvas.html +80 -0
- package/src/renderer/components/App.jsx +303 -0
- package/src/renderer/components/AppRoot.jsx +37 -0
- package/src/renderer/components/AudioDeviceSettings.jsx +145 -0
- package/src/renderer/components/EffectsPanelWrapper.jsx +267 -0
- package/src/renderer/components/MixerTab.jsx +233 -0
- package/src/renderer/components/MixerTabWrapper.jsx +31 -0
- package/src/renderer/components/PortalSelect.jsx +239 -0
- package/src/renderer/components/QueueTab.jsx +116 -0
- package/src/renderer/components/RequestsListWrapper.jsx +78 -0
- package/src/renderer/components/ServerTab.jsx +472 -0
- package/src/renderer/components/SongInfoBarWrapper.jsx +77 -0
- package/src/renderer/components/StatusBar.jsx +92 -0
- package/src/renderer/components/TabNavigation.jsx +77 -0
- package/src/renderer/components/TransportControlsWrapper.jsx +69 -0
- package/src/renderer/components/creator/CreateTab.jsx +1236 -0
- package/src/renderer/dist/assets/kaiPlayer-CoMx__a_.js +2 -0
- package/src/renderer/dist/assets/kaiPlayer-CoMx__a_.js.map +1 -0
- package/src/renderer/dist/assets/microphoneEngine-BaCUhhQc.js +2 -0
- package/src/renderer/dist/assets/microphoneEngine-BaCUhhQc.js.map +1 -0
- package/src/renderer/dist/assets/player-DVrqp7N5.js +3 -0
- package/src/renderer/dist/assets/player-DVrqp7N5.js.map +1 -0
- package/src/renderer/dist/assets/songLoaders-BaTgGib4.js +2 -0
- package/src/renderer/dist/assets/songLoaders-BaTgGib4.js.map +1 -0
- package/src/renderer/dist/assets/webrtcManager-BhCHWceK.js +2 -0
- package/src/renderer/dist/assets/webrtcManager-BhCHWceK.js.map +1 -0
- package/src/renderer/dist/js/autoTuneWorklet.js +224 -0
- package/src/renderer/dist/js/micPitchDetectorWorklet.js +137 -0
- package/src/renderer/dist/js/musicAnalysisWorklet.js +216 -0
- package/src/renderer/dist/js/phaseVocoderWorklet.js +341 -0
- package/src/renderer/dist/js/soundtouch-worklet.js +1395 -0
- package/src/renderer/dist/renderer.css +1 -0
- package/src/renderer/dist/renderer.js +62 -0
- package/src/renderer/dist/renderer.js.map +1 -0
- package/src/renderer/dist/renderer.woff2 +0 -0
- package/src/renderer/hooks/useKeyboardShortcuts.js +154 -0
- package/src/renderer/index.html +24 -0
- package/src/renderer/index.html.backup +372 -0
- package/src/renderer/js/PlayerInterface.js +267 -0
- package/src/renderer/js/autoTuneWorklet.js +224 -0
- package/src/renderer/js/butterchurnVerify.js +46 -0
- package/src/renderer/js/canvas-app.js +114 -0
- package/src/renderer/js/cdgPlayer.js +685 -0
- package/src/renderer/js/kaiPlayer.js +1200 -0
- package/src/renderer/js/karaokeRenderer.js +3392 -0
- package/src/renderer/js/micPitchDetectorWorklet.js +137 -0
- package/src/renderer/js/microphoneEngine.js +656 -0
- package/src/renderer/js/musicAnalysisWorklet.js +216 -0
- package/src/renderer/js/phaseVocoderWorklet.js +341 -0
- package/src/renderer/js/player.js +232 -0
- package/src/renderer/js/referencePitchTracker.js +130 -0
- package/src/renderer/js/songLoaders.js +334 -0
- package/src/renderer/js/soundtouch-worklet.js +1395 -0
- package/src/renderer/js/webrtcManager.js +511 -0
- package/src/renderer/lib/butterchurn.min.js +6739 -0
- package/src/renderer/lib/butterchurnPresets.min.js +1 -0
- package/src/renderer/lib/cdgraphics-wrapper.js +16 -0
- package/src/renderer/lib/cdgraphics.js +299 -0
- package/src/renderer/public/js/autoTuneWorklet.js +224 -0
- package/src/renderer/public/js/micPitchDetectorWorklet.js +137 -0
- package/src/renderer/public/js/musicAnalysisWorklet.js +216 -0
- package/src/renderer/public/js/phaseVocoderWorklet.js +341 -0
- package/src/renderer/public/js/soundtouch-worklet.js +1395 -0
- package/src/renderer/react-entry.jsx +44 -0
- package/src/renderer/styles/tailwind.css +106 -0
- package/src/renderer/utils/qrCodeGenerator.js +98 -0
- package/src/renderer/vite.config.js +31 -0
- package/src/shared/adapters/BridgeInterface.js +195 -0
- package/src/shared/components/EffectsPanel.jsx +177 -0
- package/src/shared/components/LibraryPanel.jsx +701 -0
- package/src/shared/components/LineDetailCanvas.jsx +167 -0
- package/src/shared/components/LyricLine.jsx +505 -0
- package/src/shared/components/LyricRejection.jsx +84 -0
- package/src/shared/components/LyricSuggestion.jsx +80 -0
- package/src/shared/components/LyricsEditorCanvas.jsx +271 -0
- package/src/shared/components/MixerPanel.jsx +94 -0
- package/src/shared/components/PlayerControls.jsx +206 -0
- package/src/shared/components/PortalSelect.jsx +239 -0
- package/src/shared/components/QueueList.jsx +365 -0
- package/src/shared/components/QuickSearch.jsx +126 -0
- package/src/shared/components/RequestsList.jsx +121 -0
- package/src/shared/components/SongEditor.jsx +1362 -0
- package/src/shared/components/SongInfoBar.jsx +81 -0
- package/src/shared/components/ThemeToggle.jsx +106 -0
- package/src/shared/components/Toast.jsx +30 -0
- package/src/shared/components/VisualizationSettings.jsx +243 -0
- package/src/shared/constants.js +95 -0
- package/src/shared/context/BridgeContext.jsx +32 -0
- package/src/shared/contexts/AudioContext.jsx +37 -0
- package/src/shared/contexts/PlayerContext.jsx +66 -0
- package/src/shared/contexts/SettingsContext.jsx +50 -0
- package/src/shared/defaults.js +158 -0
- package/src/shared/formatUtils.js +59 -0
- package/src/shared/formatUtils.test.js +207 -0
- package/src/shared/hooks/useAppState.js +97 -0
- package/src/shared/hooks/useAudioEngine.js +264 -0
- package/src/shared/hooks/usePlayer.js +89 -0
- package/src/shared/hooks/useSettingsPersistence.js +74 -0
- package/src/shared/hooks/useWebRTC.js +118 -0
- package/src/shared/ipcContracts.js +299 -0
- package/src/shared/package.json +3 -0
- package/src/shared/services/creatorService.js +373 -0
- package/src/shared/services/creatorService.test.js +413 -0
- package/src/shared/services/editorService.js +213 -0
- package/src/shared/services/editorService.test.js +219 -0
- package/src/shared/services/effectsService.js +271 -0
- package/src/shared/services/effectsService.test.js +418 -0
- package/src/shared/services/libraryService.js +438 -0
- package/src/shared/services/libraryService.test.js +474 -0
- package/src/shared/services/mixerService.js +172 -0
- package/src/shared/services/mixerService.test.js +399 -0
- package/src/shared/services/playerService.js +221 -0
- package/src/shared/services/playerService.test.js +357 -0
- package/src/shared/services/preferencesService.js +219 -0
- package/src/shared/services/queueService.js +226 -0
- package/src/shared/services/queueService.test.js +430 -0
- package/src/shared/services/requestsService.js +155 -0
- package/src/shared/services/requestsService.test.js +362 -0
- package/src/shared/services/serverSettingsService.js +151 -0
- package/src/shared/services/settingsService.js +257 -0
- package/src/shared/services/settingsService.test.js +295 -0
- package/src/shared/state/StateManager.js +263 -0
- package/src/shared/utils/audio.js +42 -0
- package/src/shared/utils/format.js +32 -0
- package/src/shared/utils/lyricsUtils.js +162 -0
- package/src/test/setup.js +40 -0
- package/src/utils/cdgLoader.js +180 -0
- package/src/utils/m4aLoader.js +333 -0
- package/src/web/App.jsx +578 -0
- package/src/web/adapters/WebBridge.js +428 -0
- package/src/web/components/PlayerSettingsPanel.jsx +231 -0
- package/src/web/components/SongSearch.jsx +180 -0
- package/src/web/dist/assets/index-0H-RnRrV.js +51 -0
- package/src/web/dist/assets/index-0H-RnRrV.js.map +1 -0
- package/src/web/dist/assets/index-DYW2zB0u.css +1 -0
- package/src/web/dist/index.html +15 -0
- package/src/web/index.html +14 -0
- package/src/web/main.jsx +10 -0
- package/src/web/package-lock.json +1765 -0
- package/src/web/pages/SongRequestPage.jsx +619 -0
- package/src/web/styles/tailwind.css +68 -0
- package/src/web/vite.config.js +27 -0
- package/static/fonts/material-icons.woff2 +0 -0
- package/static/images/butterchurn-screenshots/Aderrasi - Potion of Spirits.png +0 -0
- package/static/images/butterchurn-screenshots/Aderrasi - Songflower _Moss Posy_.png +0 -0
- package/static/images/butterchurn-screenshots/Aderrasi - Storm of the Eye _Thunder_ - mash0000 - quasi pseudo meta concentrics.png +0 -0
- package/static/images/butterchurn-screenshots/Aderrasi _ Geiss - Airhandler _Kali Mix_ - Canvas Mix.png +0 -0
- package/static/images/butterchurn-screenshots/An AdamFX n Martin Infusion 2 flexi - Why The Sky Looks Diffrent Today - AdamFx n Martin Infusion - Tack Tile Disfunction B.png +0 -0
- package/static/images/butterchurn-screenshots/Cope - The Neverending Explosion of Red Liquid Fire.png +0 -0
- proton lights __Krash_s beat code_ _Phat_remix02b.png +0 -0
- package/static/images/butterchurn-screenshots/Eo_S_ _ Phat - cubetrace - v2.png +0 -0
- package/static/images/butterchurn-screenshots/Eo_S_ _ Zylot - skylight _Stained Glass Majesty mix_.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi - alien fish pond.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi - area 51.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi - infused with the spiral.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi - mindblob _shiny mix_.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi - mindblob mix.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi - predator-prey-spirals.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi - smashing fractals _acid etching mix_.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi - truly soft piece of software - this is generic texturing _Jelly_ .png +0 -0
- package/static/images/butterchurn-screenshots/Flexi _ Martin - astral projection.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi _ Martin - cascading decay swing.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi _ amandio c - piercing 05 - Kopie _2_ - Kopie.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi _ stahlregen - jelly showoff parade.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi_ fishbrain_ Geiss _ Martin - tokamak witchery.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi_ martin _ geiss - dedicated to the sherwin maxawow.png +0 -0
- package/static/images/butterchurn-screenshots/Fumbling_Foo _ Flexi_ Martin_ Orb_ Unchained - Star Nova v7b.png +0 -0
- package/static/images/butterchurn-screenshots/Geiss - Cauldron - painterly 2 _saturation remix_.png +0 -0
- package/static/images/butterchurn-screenshots/Geiss - Reaction Diffusion 2.png +0 -0
- package/static/images/butterchurn-screenshots/Geiss - Spiral Artifact.png +0 -0
- package/static/images/butterchurn-screenshots/Geiss - Thumb Drum.png +0 -0
- package/static/images/butterchurn-screenshots/Geiss _ Flexi _ Martin - disconnected.png +0 -0
- package/static/images/butterchurn-screenshots/Geiss_ Flexi _ Stahlregen - Thumbdrum Tokamak _crossfiring aftermath jelly mashup_.png +0 -0
- package/static/images/butterchurn-screenshots/Goody - The Wild Vort.png +0 -0
- package/static/images/butterchurn-screenshots/Idiot - Star Of Annon.png +0 -0
- package/static/images/butterchurn-screenshots/Krash _ Illusion - Spiral Movement.png +0 -0
- package/static/images/butterchurn-screenshots/Martin - QBikal - Surface Turbulence IIb.png +0 -0
- package/static/images/butterchurn-screenshots/Martin - acid wiring.png +0 -0
- package/static/images/butterchurn-screenshots/Martin - charisma.png +0 -0
- package/static/images/butterchurn-screenshots/Martin - liquid arrows.png +0 -0
- package/static/images/butterchurn-screenshots/Milk Artist At our Best - FED - SlowFast Ft AdamFX n Martin - HD CosmoFX.png +0 -0
- package/static/images/butterchurn-screenshots/ORB - Waaa.png +0 -0
- package/static/images/butterchurn-screenshots/Phat_fiShbRaiN_Eo_S_Mandala_Chasers_remix.png +0 -0
- package/static/images/butterchurn-screenshots/Rovastar - Oozing Resistance.png +0 -0
- package/static/images/butterchurn-screenshots/Rovastar _ Loadus _ Geiss - FractalDrop _Triple Mix_.png +0 -0
- package/static/images/butterchurn-screenshots/TonyMilkdrop - Leonardo Da Vinci_s Balloon _Flexi - merry-go-round _ techstyle_.png +0 -0
- package/static/images/butterchurn-screenshots/TonyMilkdrop - Magellan_s Nebula _Flexi - you enter first _ multiverse_.png +0 -0
- package/static/images/butterchurn-screenshots/Unchained - Rewop.png +0 -0
- package/static/images/butterchurn-screenshots/Unchained - Unified Drag 2.png +0 -0
- package/static/images/butterchurn-screenshots/Unchained _ Rovastar - Wormhole Pillars _Hall of Shadows mix_.png +0 -0
- package/static/images/butterchurn-screenshots/Zylot - Paint Spill _Music Reactive Paint Mix_.png +0 -0
- package/static/images/butterchurn-screenshots/Zylot - Star Ornament.png +0 -0
- package/static/images/butterchurn-screenshots/Zylot - True Visionary _Final Mix_.png +0 -0
- package/static/images/butterchurn-screenshots/_Aderrasi - Wanderer in Curved Space - mash0000 - faclempt kibitzing meshuggana schmaltz _Geiss color mix_.png +0 -0
- package/static/images/butterchurn-screenshots/_Geiss - Artifact 01.png +0 -0
- package/static/images/butterchurn-screenshots/_Geiss - Desert Rose 2.png +0 -0
- package/static/images/butterchurn-screenshots/_Geiss - untitled.png +0 -0
- package/static/images/butterchurn-screenshots/_Mig_049.png +0 -0
- package/static/images/butterchurn-screenshots/_Mig_085.png +0 -0
- package/static/images/butterchurn-screenshots/_Rovastar _ Geiss - Hurricane Nightmare _Posterize Mix_.png +0 -0
- package/static/images/butterchurn-screenshots/___ Royal - Mashup _197_.png +0 -0
- package/static/images/butterchurn-screenshots/___ Royal - Mashup _220_.png +0 -0
- package/static/images/butterchurn-screenshots/___ Royal - Mashup _431_.png +0 -0
- package/static/images/butterchurn-screenshots/cope _ martin - mother-of-pearl.png +0 -0
- package/static/images/butterchurn-screenshots/fiShbRaiN _ Flexi - witchcraft 2_0.png +0 -0
- package/static/images/butterchurn-screenshots/flexi - bouncing balls _double mindblob neon mix_.png +0 -0
- package/static/images/butterchurn-screenshots/flexi - mom_ why the sky looks different today.png +0 -0
- package/static/images/butterchurn-screenshots/flexi - patternton_ district of media_ capitol of the united abstractions of fractopia.png +0 -0
- package/static/images/butterchurn-screenshots/flexi - swing out on the spiral.png +0 -0
- package/static/images/butterchurn-screenshots/flexi - what is the matrix.png +0 -0
- package/static/images/butterchurn-screenshots/flexi _ amandio c - organic _random mashup_.png +0 -0
- package/static/images/butterchurn-screenshots/flexi _ amandio c - organic12-3d-2_milk.png +0 -0
- package/static/images/butterchurn-screenshots/flexi _ fishbrain - neon mindblob grafitti.png +0 -0
- package/static/images/butterchurn-screenshots/flexi _ geiss - pogo cubes vs_ tokamak vs_ game of life _stahls jelly 4_5 finish_.png +0 -0
- package/static/images/butterchurn-screenshots/high-altitude basket unraveling - singh grooves nitrogen argon nz_.png +0 -0
- package/static/images/butterchurn-screenshots/martin - The Bridge of Khazad-Dum.png +0 -0
- package/static/images/butterchurn-screenshots/martin - angel flight.png +0 -0
- package/static/images/butterchurn-screenshots/martin - another kind of groove.png +0 -0
- package/static/images/butterchurn-screenshots/martin - bombyx mori.png +0 -0
- package/static/images/butterchurn-screenshots/martin - castle in the air.png +0 -0
- package/static/images/butterchurn-screenshots/martin - chain breaker.png +0 -0
- package/static/images/butterchurn-screenshots/martin - disco mix 4.png +0 -0
- package/static/images/butterchurn-screenshots/martin - extreme heat.png +0 -0
- package/static/images/butterchurn-screenshots/martin - frosty caves 2.png +0 -0
- package/static/images/butterchurn-screenshots/martin - fruit machine.png +0 -0
- package/static/images/butterchurn-screenshots/martin - ghost city.png +0 -0
- package/static/images/butterchurn-screenshots/martin - glass corridor.png +0 -0
- package/static/images/butterchurn-screenshots/martin - infinity _2010 update_.png +0 -0
- package/static/images/butterchurn-screenshots/martin - mandelbox explorer - high speed demo version.png +0 -0
- package/static/images/butterchurn-screenshots/martin - mucus cervix.png +0 -0
- package/static/images/butterchurn-screenshots/martin - reflections on black tiles.png +0 -0
- package/static/images/butterchurn-screenshots/martin - stormy sea _2010 update_.png +0 -0
- package/static/images/butterchurn-screenshots/martin - witchcraft reloaded.png +0 -0
- package/static/images/butterchurn-screenshots/martin _ flexi - diamond cutter _prismaticvortex_com_ - camille - i wish i wish i wish i was constrained.png +0 -0
- package/static/images/butterchurn-screenshots/martin _shadow harlequins shape code_ - fata morgana.png +0 -0
- package/static/images/butterchurn-screenshots/martin_ flexi_ fishbrain _ sto - enterstate _random mashup_.png +0 -0
- package/static/images/butterchurn-screenshots/sawtooth grin roam.png +0 -0
- package/static/images/butterchurn-screenshots/shifter - dark tides bdrv mix 2.png +0 -0
- package/static/images/butterchurn-screenshots/suksma - Rovastar - Sunflower Passion _Enlightment Mix__Phat_edit _ flexi und martin shaders - circumflex in character classes in regular expression.png +0 -0
- package/static/images/butterchurn-screenshots/suksma - heretical crosscut playpen.png +0 -0
- package/static/images/butterchurn-screenshots/suksma - uninitialized variabowl _hydroponic chronic_.png +0 -0
- package/static/images/butterchurn-screenshots/suksma - vector exp 1 - couldn_t not.png +0 -0
- package/static/images/butterchurn-screenshots/yin - 191 - Temporal singularities.png +0 -0
- package/static/images/logo-512.png +0 -0
- package/static/images/logo.png +0 -0
- package/static/loukai-logo.png +0 -0
- package/static/screenshot-generator.html +610 -0
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Library Service Tests
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
6
|
+
import * as libraryService from './libraryService.js';
|
|
7
|
+
|
|
8
|
+
// Mock MainApp for testing
|
|
9
|
+
class MockMainApp {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.cachedLibrary = null;
|
|
12
|
+
this.settings = {
|
|
13
|
+
getSongsFolder: vi.fn(),
|
|
14
|
+
};
|
|
15
|
+
this.webServer = null;
|
|
16
|
+
this.scanForKaiFiles = vi.fn();
|
|
17
|
+
this.scanForKaiFilesWithProgress = vi.fn();
|
|
18
|
+
this.findAllKaiFiles = vi.fn();
|
|
19
|
+
this.scanFilesystemForSync = vi.fn();
|
|
20
|
+
this.parseMetadataWithProgress = vi.fn();
|
|
21
|
+
this.extractM4AMetadata = vi.fn();
|
|
22
|
+
this.extractCDGArchiveMetadata = vi.fn();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe('libraryService', () => {
|
|
27
|
+
let mainApp;
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
mainApp = new MockMainApp();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('getSongsFolder', () => {
|
|
34
|
+
it('should return the songs folder path', () => {
|
|
35
|
+
mainApp.settings.getSongsFolder.mockReturnValue('/music/karaoke');
|
|
36
|
+
|
|
37
|
+
const result = libraryService.getSongsFolder(mainApp);
|
|
38
|
+
|
|
39
|
+
expect(result.success).toBe(true);
|
|
40
|
+
expect(result.folder).toBe('/music/karaoke');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should return null if folder not set', () => {
|
|
44
|
+
mainApp.settings.getSongsFolder.mockReturnValue(null);
|
|
45
|
+
|
|
46
|
+
const result = libraryService.getSongsFolder(mainApp);
|
|
47
|
+
|
|
48
|
+
expect(result.success).toBe(true);
|
|
49
|
+
expect(result.folder).toBeNull();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('should handle errors gracefully', () => {
|
|
53
|
+
mainApp.settings.getSongsFolder.mockImplementation(() => {
|
|
54
|
+
throw new Error('Settings not available');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const result = libraryService.getSongsFolder(mainApp);
|
|
58
|
+
|
|
59
|
+
expect(result.success).toBe(false);
|
|
60
|
+
expect(result.error).toBe('Settings not available');
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('getCachedSongs', () => {
|
|
65
|
+
it('should return cached songs when available', () => {
|
|
66
|
+
const mockSongs = [
|
|
67
|
+
{ title: 'Song 1', artist: 'Artist 1', path: '/music/song1.kai' },
|
|
68
|
+
{ title: 'Song 2', artist: 'Artist 2', path: '/music/song2.kai' },
|
|
69
|
+
];
|
|
70
|
+
mainApp.cachedLibrary = mockSongs;
|
|
71
|
+
|
|
72
|
+
const result = libraryService.getCachedSongs(mainApp);
|
|
73
|
+
|
|
74
|
+
expect(result.success).toBe(true);
|
|
75
|
+
expect(result.files).toEqual(mockSongs);
|
|
76
|
+
expect(result.cached).toBe(true);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('should return empty array when no cache', () => {
|
|
80
|
+
const result = libraryService.getCachedSongs(mainApp);
|
|
81
|
+
|
|
82
|
+
expect(result.success).toBe(true);
|
|
83
|
+
expect(result.files).toEqual([]);
|
|
84
|
+
expect(result.cached).toBe(false);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('getLibrarySongs', () => {
|
|
89
|
+
it('should return cached library if available', async () => {
|
|
90
|
+
const mockSongs = [{ title: 'Cached Song', path: '/music/cached.kai' }];
|
|
91
|
+
mainApp.cachedLibrary = mockSongs;
|
|
92
|
+
|
|
93
|
+
const result = await libraryService.getLibrarySongs(mainApp);
|
|
94
|
+
|
|
95
|
+
expect(result.success).toBe(true);
|
|
96
|
+
expect(result.songs).toEqual(mockSongs);
|
|
97
|
+
expect(result.fromCache).toBe(true);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('should scan when cache is empty', async () => {
|
|
101
|
+
const mockSongs = [{ title: 'Scanned Song', path: '/music/scanned.kai' }];
|
|
102
|
+
mainApp.settings.getSongsFolder.mockReturnValue('/music/karaoke');
|
|
103
|
+
mainApp.scanForKaiFiles.mockResolvedValue(mockSongs);
|
|
104
|
+
|
|
105
|
+
const result = await libraryService.getLibrarySongs(mainApp);
|
|
106
|
+
|
|
107
|
+
expect(result.success).toBe(true);
|
|
108
|
+
expect(result.songs).toEqual(mockSongs);
|
|
109
|
+
expect(result.fromCache).toBe(false);
|
|
110
|
+
expect(mainApp.scanForKaiFiles).toHaveBeenCalledWith('/music/karaoke');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('should return error when songs folder not set', async () => {
|
|
114
|
+
mainApp.settings.getSongsFolder.mockReturnValue(null);
|
|
115
|
+
|
|
116
|
+
const result = await libraryService.getLibrarySongs(mainApp);
|
|
117
|
+
|
|
118
|
+
expect(result.success).toBe(false);
|
|
119
|
+
expect(result.error).toBe('Songs folder not set');
|
|
120
|
+
expect(result.songs).toEqual([]);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('should handle scan errors gracefully', async () => {
|
|
124
|
+
mainApp.settings.getSongsFolder.mockReturnValue('/music/karaoke');
|
|
125
|
+
mainApp.scanForKaiFiles.mockRejectedValue(new Error('Scan failed'));
|
|
126
|
+
|
|
127
|
+
const result = await libraryService.getLibrarySongs(mainApp);
|
|
128
|
+
|
|
129
|
+
expect(result.success).toBe(false);
|
|
130
|
+
expect(result.error).toBe('Scan failed');
|
|
131
|
+
expect(result.songs).toEqual([]);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
describe('scanLibrary', () => {
|
|
136
|
+
it('should scan library and cache results', async () => {
|
|
137
|
+
const mockFiles = [
|
|
138
|
+
{ title: 'Song 1', path: '/music/song1.kai' },
|
|
139
|
+
{ title: 'Song 2', path: '/music/song2.kai' },
|
|
140
|
+
];
|
|
141
|
+
mainApp.settings.getSongsFolder.mockReturnValue('/music/karaoke');
|
|
142
|
+
mainApp.findAllKaiFiles.mockResolvedValue(mockFiles);
|
|
143
|
+
mainApp.scanForKaiFilesWithProgress.mockResolvedValue(mockFiles);
|
|
144
|
+
|
|
145
|
+
const result = await libraryService.scanLibrary(mainApp);
|
|
146
|
+
|
|
147
|
+
expect(result.success).toBe(true);
|
|
148
|
+
expect(result.files).toEqual(mockFiles);
|
|
149
|
+
expect(result.count).toBe(2);
|
|
150
|
+
expect(result.cached).toBe(true);
|
|
151
|
+
expect(mainApp.cachedLibrary).toEqual(mockFiles);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('should call progress callback during scan', async () => {
|
|
155
|
+
const mockFiles = [{ title: 'Song 1', path: '/music/song1.kai' }];
|
|
156
|
+
mainApp.settings.getSongsFolder.mockReturnValue('/music/karaoke');
|
|
157
|
+
mainApp.findAllKaiFiles.mockResolvedValue(mockFiles);
|
|
158
|
+
mainApp.scanForKaiFilesWithProgress.mockResolvedValue(mockFiles);
|
|
159
|
+
|
|
160
|
+
const progressCallback = vi.fn();
|
|
161
|
+
await libraryService.scanLibrary(mainApp, progressCallback);
|
|
162
|
+
|
|
163
|
+
expect(progressCallback).toHaveBeenCalledWith({ current: 0, total: 1 });
|
|
164
|
+
expect(progressCallback).toHaveBeenCalledWith({ current: 1, total: 1 });
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('should return error when songs folder not set', async () => {
|
|
168
|
+
mainApp.settings.getSongsFolder.mockReturnValue(null);
|
|
169
|
+
|
|
170
|
+
const result = await libraryService.scanLibrary(mainApp);
|
|
171
|
+
|
|
172
|
+
expect(result.success).toBe(false);
|
|
173
|
+
expect(result.error).toBe('Songs folder not set');
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('should handle scan errors gracefully', async () => {
|
|
177
|
+
mainApp.settings.getSongsFolder.mockReturnValue('/music/karaoke');
|
|
178
|
+
mainApp.findAllKaiFiles.mockRejectedValue(new Error('Access denied'));
|
|
179
|
+
|
|
180
|
+
const result = await libraryService.scanLibrary(mainApp);
|
|
181
|
+
|
|
182
|
+
expect(result.success).toBe(false);
|
|
183
|
+
expect(result.error).toBe('Access denied');
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
describe('syncLibrary', () => {
|
|
188
|
+
it('should sync library incrementally', async () => {
|
|
189
|
+
const cachedFiles = [{ title: 'Old Song', path: '/music/old.kai', file: '/music/old.kai' }];
|
|
190
|
+
const filesystemScan = [
|
|
191
|
+
{ path: '/music/old.kai' }, // Still exists
|
|
192
|
+
{ path: '/music/new.kai' }, // New file
|
|
193
|
+
];
|
|
194
|
+
const newMetadata = [{ title: 'New Song', path: '/music/new.kai', file: '/music/new.kai' }];
|
|
195
|
+
|
|
196
|
+
mainApp.cachedLibrary = cachedFiles;
|
|
197
|
+
mainApp.settings.getSongsFolder.mockReturnValue('/music/karaoke');
|
|
198
|
+
mainApp.scanFilesystemForSync.mockResolvedValue(filesystemScan);
|
|
199
|
+
mainApp.parseMetadataWithProgress.mockResolvedValue(newMetadata);
|
|
200
|
+
|
|
201
|
+
const result = await libraryService.syncLibrary(mainApp);
|
|
202
|
+
|
|
203
|
+
expect(result.success).toBe(true);
|
|
204
|
+
expect(result.count).toBe(2);
|
|
205
|
+
expect(result.added).toBe(1);
|
|
206
|
+
expect(result.removed).toBe(0);
|
|
207
|
+
expect(mainApp.cachedLibrary).toHaveLength(2);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('should detect removed files', async () => {
|
|
211
|
+
const cachedFiles = [
|
|
212
|
+
{ title: 'Song 1', path: '/music/song1.kai', file: '/music/song1.kai' },
|
|
213
|
+
{ title: 'Song 2', path: '/music/song2.kai', file: '/music/song2.kai' },
|
|
214
|
+
];
|
|
215
|
+
const filesystemScan = [
|
|
216
|
+
{ path: '/music/song1.kai' }, // Song 2 was removed
|
|
217
|
+
];
|
|
218
|
+
|
|
219
|
+
mainApp.cachedLibrary = cachedFiles;
|
|
220
|
+
mainApp.settings.getSongsFolder.mockReturnValue('/music/karaoke');
|
|
221
|
+
mainApp.scanFilesystemForSync.mockResolvedValue(filesystemScan);
|
|
222
|
+
mainApp.parseMetadataWithProgress.mockResolvedValue([]);
|
|
223
|
+
|
|
224
|
+
const result = await libraryService.syncLibrary(mainApp);
|
|
225
|
+
|
|
226
|
+
expect(result.success).toBe(true);
|
|
227
|
+
expect(result.count).toBe(1);
|
|
228
|
+
expect(result.added).toBe(0);
|
|
229
|
+
expect(result.removed).toBe(1);
|
|
230
|
+
expect(result.removedPaths).toContain('/music/song2.kai');
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('should call progress callback during sync', async () => {
|
|
234
|
+
mainApp.settings.getSongsFolder.mockReturnValue('/music/karaoke');
|
|
235
|
+
mainApp.scanFilesystemForSync.mockResolvedValue([]);
|
|
236
|
+
mainApp.parseMetadataWithProgress.mockResolvedValue([]);
|
|
237
|
+
|
|
238
|
+
const progressCallback = vi.fn();
|
|
239
|
+
await libraryService.syncLibrary(mainApp, progressCallback);
|
|
240
|
+
|
|
241
|
+
expect(progressCallback).toHaveBeenCalled();
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('should return error when songs folder not set', async () => {
|
|
245
|
+
mainApp.settings.getSongsFolder.mockReturnValue(null);
|
|
246
|
+
|
|
247
|
+
const result = await libraryService.syncLibrary(mainApp);
|
|
248
|
+
|
|
249
|
+
expect(result.success).toBe(false);
|
|
250
|
+
expect(result.error).toBe('Songs folder not set');
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it('should handle sync errors gracefully', async () => {
|
|
254
|
+
mainApp.settings.getSongsFolder.mockReturnValue('/music/karaoke');
|
|
255
|
+
mainApp.scanFilesystemForSync.mockRejectedValue(new Error('Sync failed'));
|
|
256
|
+
|
|
257
|
+
const result = await libraryService.syncLibrary(mainApp);
|
|
258
|
+
|
|
259
|
+
expect(result.success).toBe(false);
|
|
260
|
+
expect(result.error).toBe('Sync failed');
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
describe('searchSongs', () => {
|
|
265
|
+
beforeEach(() => {
|
|
266
|
+
mainApp.cachedLibrary = [
|
|
267
|
+
{ title: 'Dancing Queen', artist: 'ABBA', album: 'Arrival' },
|
|
268
|
+
{ title: 'Bohemian Rhapsody', artist: 'Queen', album: 'A Night at the Opera' },
|
|
269
|
+
{ title: 'Hotel California', artist: 'Eagles', album: 'Hotel California' },
|
|
270
|
+
{ title: 'Stairway to Heaven', artist: 'Led Zeppelin', album: 'Led Zeppelin IV' },
|
|
271
|
+
];
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it('should find songs by title', () => {
|
|
275
|
+
const result = libraryService.searchSongs(mainApp, 'queen');
|
|
276
|
+
|
|
277
|
+
expect(result.success).toBe(true);
|
|
278
|
+
expect(result.songs).toHaveLength(2);
|
|
279
|
+
expect(result.songs[0].title).toBe('Dancing Queen'); // Title match first
|
|
280
|
+
expect(result.songs[1].title).toBe('Bohemian Rhapsody'); // Artist match second
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it('should find songs by artist', () => {
|
|
284
|
+
const result = libraryService.searchSongs(mainApp, 'eagles');
|
|
285
|
+
|
|
286
|
+
expect(result.success).toBe(true);
|
|
287
|
+
expect(result.songs).toHaveLength(1);
|
|
288
|
+
expect(result.songs[0].title).toBe('Hotel California');
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it('should find songs by album', () => {
|
|
292
|
+
const result = libraryService.searchSongs(mainApp, 'arrival');
|
|
293
|
+
|
|
294
|
+
expect(result.success).toBe(true);
|
|
295
|
+
expect(result.songs).toHaveLength(1);
|
|
296
|
+
expect(result.songs[0].title).toBe('Dancing Queen');
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it('should return empty array for empty query', () => {
|
|
300
|
+
const result = libraryService.searchSongs(mainApp, '');
|
|
301
|
+
|
|
302
|
+
expect(result.success).toBe(true);
|
|
303
|
+
expect(result.songs).toEqual([]);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it('should return empty array when no cache', () => {
|
|
307
|
+
mainApp.cachedLibrary = null;
|
|
308
|
+
const result = libraryService.searchSongs(mainApp, 'test');
|
|
309
|
+
|
|
310
|
+
expect(result.success).toBe(true);
|
|
311
|
+
expect(result.songs).toEqual([]);
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it('should limit results to 50 songs', () => {
|
|
315
|
+
// Create 60 songs
|
|
316
|
+
mainApp.cachedLibrary = Array.from({ length: 60 }, (_, i) => ({
|
|
317
|
+
title: `Test Song ${i}`,
|
|
318
|
+
artist: 'Test Artist',
|
|
319
|
+
}));
|
|
320
|
+
|
|
321
|
+
const result = libraryService.searchSongs(mainApp, 'test');
|
|
322
|
+
|
|
323
|
+
expect(result.success).toBe(true);
|
|
324
|
+
expect(result.songs).toHaveLength(50);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it('should prioritize title matches over artist/album matches', () => {
|
|
328
|
+
const result = libraryService.searchSongs(mainApp, 'california');
|
|
329
|
+
|
|
330
|
+
expect(result.success).toBe(true);
|
|
331
|
+
expect(result.songs).toHaveLength(1);
|
|
332
|
+
expect(result.songs[0].title).toBe('Hotel California');
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it('should handle search errors gracefully', () => {
|
|
336
|
+
// Simulate error by setting cachedLibrary to invalid data
|
|
337
|
+
mainApp.cachedLibrary = [{ invalid: 'data' }];
|
|
338
|
+
mainApp.cachedLibrary.filter = () => {
|
|
339
|
+
throw new Error('Search failed');
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const result = libraryService.searchSongs(mainApp, 'test');
|
|
343
|
+
|
|
344
|
+
expect(result.success).toBe(false);
|
|
345
|
+
expect(result.error).toBe('Search failed');
|
|
346
|
+
expect(result.songs).toEqual([]);
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
describe('getSongInfo', () => {
|
|
351
|
+
it('should return song from cache if available', async () => {
|
|
352
|
+
const mockSong = { title: 'Test Song', path: '/music/test.kai' };
|
|
353
|
+
mainApp.cachedLibrary = [mockSong];
|
|
354
|
+
|
|
355
|
+
const result = await libraryService.getSongInfo(mainApp, '/music/test.kai');
|
|
356
|
+
|
|
357
|
+
expect(result.success).toBe(true);
|
|
358
|
+
expect(result.song).toEqual(mockSong);
|
|
359
|
+
expect(result.fromCache).toBe(true);
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it('should extract metadata for M4A file not in cache', async () => {
|
|
363
|
+
const mockMetadata = { title: 'New Song', artist: 'New Artist', hasKaraoke: true };
|
|
364
|
+
mainApp.extractM4AMetadata.mockResolvedValue(mockMetadata);
|
|
365
|
+
|
|
366
|
+
const result = await libraryService.getSongInfo(mainApp, '/music/new.m4a');
|
|
367
|
+
|
|
368
|
+
expect(result.success).toBe(true);
|
|
369
|
+
expect(result.song.title).toBe('New Song');
|
|
370
|
+
expect(result.song.format).toBe('m4a-stems');
|
|
371
|
+
expect(result.fromCache).toBe(false);
|
|
372
|
+
expect(mainApp.extractM4AMetadata).toHaveBeenCalledWith('/music/new.m4a');
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it('should extract metadata for CDG archive', async () => {
|
|
376
|
+
const mockMetadata = { title: 'Archive Song', artist: 'Archive Artist' };
|
|
377
|
+
mainApp.extractCDGArchiveMetadata.mockResolvedValue(mockMetadata);
|
|
378
|
+
|
|
379
|
+
const result = await libraryService.getSongInfo(mainApp, '/music/archive.kar');
|
|
380
|
+
|
|
381
|
+
expect(result.success).toBe(true);
|
|
382
|
+
expect(result.song.title).toBe('Archive Song');
|
|
383
|
+
expect(result.song.format).toBe('cdg-archive');
|
|
384
|
+
expect(mainApp.extractCDGArchiveMetadata).toHaveBeenCalledWith('/music/archive.kar');
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
it('should return error for missing file path', async () => {
|
|
388
|
+
const result = await libraryService.getSongInfo(mainApp, '');
|
|
389
|
+
|
|
390
|
+
expect(result.success).toBe(false);
|
|
391
|
+
expect(result.error).toBe('File path is required');
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
it('should return error for CDG pair (requires both files)', async () => {
|
|
395
|
+
const result = await libraryService.getSongInfo(mainApp, '/music/song.mp3');
|
|
396
|
+
|
|
397
|
+
expect(result.success).toBe(false);
|
|
398
|
+
expect(result.error).toBe('CDG pair requires both MP3 and CDG paths');
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
it('should handle metadata extraction errors', async () => {
|
|
402
|
+
mainApp.extractM4AMetadata.mockRejectedValue(new Error('Corrupt file'));
|
|
403
|
+
|
|
404
|
+
const result = await libraryService.getSongInfo(mainApp, '/music/corrupt.m4a');
|
|
405
|
+
|
|
406
|
+
expect(result.success).toBe(false);
|
|
407
|
+
expect(result.error).toBe('Corrupt file');
|
|
408
|
+
});
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
describe('clearLibraryCache', () => {
|
|
412
|
+
it('should clear the library cache', () => {
|
|
413
|
+
mainApp.cachedLibrary = [{ title: 'Test Song' }];
|
|
414
|
+
|
|
415
|
+
const result = libraryService.clearLibraryCache(mainApp);
|
|
416
|
+
|
|
417
|
+
expect(result.success).toBe(true);
|
|
418
|
+
expect(result.message).toBe('Library cache cleared');
|
|
419
|
+
expect(mainApp.cachedLibrary).toBeNull();
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
describe('updateLibraryCache', () => {
|
|
424
|
+
it('should update main app cache', async () => {
|
|
425
|
+
const mockFiles = [{ title: 'Song 1' }, { title: 'Song 2' }];
|
|
426
|
+
// Don't set settings.getSongsFolder to avoid Electron imports in tests
|
|
427
|
+
mainApp.settings = {};
|
|
428
|
+
|
|
429
|
+
const result = await libraryService.updateLibraryCache(mainApp, mockFiles);
|
|
430
|
+
|
|
431
|
+
expect(result.success).toBe(true);
|
|
432
|
+
expect(result.count).toBe(2);
|
|
433
|
+
expect(mainApp.cachedLibrary).toEqual(mockFiles);
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
it('should update web server cache if available', async () => {
|
|
437
|
+
const mockFiles = [{ title: 'Song 1' }];
|
|
438
|
+
// Don't set settings.getSongsFolder to avoid Electron imports in tests
|
|
439
|
+
mainApp.settings = {};
|
|
440
|
+
mainApp.webServer = {
|
|
441
|
+
cachedSongs: [],
|
|
442
|
+
songsCacheTime: 0,
|
|
443
|
+
fuse: {},
|
|
444
|
+
io: {
|
|
445
|
+
emit: vi.fn(),
|
|
446
|
+
},
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
const result = await libraryService.updateLibraryCache(mainApp, mockFiles);
|
|
450
|
+
|
|
451
|
+
expect(result.success).toBe(true);
|
|
452
|
+
expect(mainApp.webServer.cachedSongs).toEqual(mockFiles);
|
|
453
|
+
expect(mainApp.webServer.fuse).toBeNull();
|
|
454
|
+
expect(mainApp.webServer.io.emit).toHaveBeenCalledWith(
|
|
455
|
+
'library-refreshed',
|
|
456
|
+
expect.objectContaining({ count: 1 })
|
|
457
|
+
);
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
it('should handle errors gracefully', async () => {
|
|
461
|
+
// Simulate error by making cachedLibrary assignment fail
|
|
462
|
+
Object.defineProperty(mainApp, 'cachedLibrary', {
|
|
463
|
+
set: () => {
|
|
464
|
+
throw new Error('Cache update failed');
|
|
465
|
+
},
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
const result = await libraryService.updateLibraryCache(mainApp, []);
|
|
469
|
+
|
|
470
|
+
expect(result.success).toBe(false);
|
|
471
|
+
expect(result.error).toBe('Cache update failed');
|
|
472
|
+
});
|
|
473
|
+
});
|
|
474
|
+
});
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mixer Service - Shared business logic for mixer control
|
|
3
|
+
*
|
|
4
|
+
* Used by both IPC handlers (Electron) and REST endpoints (Web Server)
|
|
5
|
+
* to ensure consistent mixer control across all interfaces.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Get current mixer state
|
|
10
|
+
* @param {Object} appState - Application state instance
|
|
11
|
+
* @returns {Object} Result with success status and mixer state
|
|
12
|
+
*/
|
|
13
|
+
export function getMixerState(appState) {
|
|
14
|
+
try {
|
|
15
|
+
const state = appState.getSnapshot();
|
|
16
|
+
return {
|
|
17
|
+
success: true,
|
|
18
|
+
mixer: state.mixer,
|
|
19
|
+
};
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.error('Error getting mixer state:', error);
|
|
22
|
+
return {
|
|
23
|
+
success: false,
|
|
24
|
+
error: error.message,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Set master gain for a bus
|
|
31
|
+
* @param {Object} mainApp - Main application instance
|
|
32
|
+
* @param {string} bus - Bus name (PA, IEM, or mic)
|
|
33
|
+
* @param {number} gainDb - Gain in dB
|
|
34
|
+
* @returns {Object} Result with success status
|
|
35
|
+
*/
|
|
36
|
+
export function setMasterGain(mainApp, bus, gainDb) {
|
|
37
|
+
try {
|
|
38
|
+
if (!bus || typeof gainDb !== 'number') {
|
|
39
|
+
return {
|
|
40
|
+
success: false,
|
|
41
|
+
error: 'bus (PA/IEM/mic) and gainDb required',
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Update AppState immediately
|
|
46
|
+
const currentMixer = mainApp.appState.state.mixer;
|
|
47
|
+
if (currentMixer[bus]) {
|
|
48
|
+
// Create a new mixer state object with the updated bus
|
|
49
|
+
const updatedMixer = {
|
|
50
|
+
...currentMixer,
|
|
51
|
+
[bus]: {
|
|
52
|
+
...currentMixer[bus],
|
|
53
|
+
gain: gainDb,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
mainApp.appState.updateMixerState(updatedMixer);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Send to renderer to apply audio changes
|
|
60
|
+
mainApp.sendToRenderer('mixer:setMasterGain', { bus, gainDb });
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
success: true,
|
|
64
|
+
bus,
|
|
65
|
+
gainDb,
|
|
66
|
+
};
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error('Error setting master gain:', error);
|
|
69
|
+
return {
|
|
70
|
+
success: false,
|
|
71
|
+
error: error.message,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Toggle master mute for a bus
|
|
78
|
+
* @param {Object} mainApp - Main application instance
|
|
79
|
+
* @param {string} bus - Bus name (PA, IEM, or mic)
|
|
80
|
+
* @returns {Object} Result with success status and new muted state
|
|
81
|
+
*/
|
|
82
|
+
export function toggleMasterMute(mainApp, bus) {
|
|
83
|
+
try {
|
|
84
|
+
if (!bus) {
|
|
85
|
+
return {
|
|
86
|
+
success: false,
|
|
87
|
+
error: 'bus (PA/IEM/mic) required',
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Update AppState immediately (toggle mute)
|
|
92
|
+
const currentMixer = mainApp.appState.state.mixer;
|
|
93
|
+
let newMuted = false;
|
|
94
|
+
|
|
95
|
+
if (currentMixer[bus]) {
|
|
96
|
+
const oldMuted = currentMixer[bus].muted;
|
|
97
|
+
newMuted = !oldMuted;
|
|
98
|
+
|
|
99
|
+
// Create a new mixer state object with the updated bus
|
|
100
|
+
const updatedMixer = {
|
|
101
|
+
...currentMixer,
|
|
102
|
+
[bus]: {
|
|
103
|
+
...currentMixer[bus],
|
|
104
|
+
muted: newMuted,
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
mainApp.appState.updateMixerState(updatedMixer);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Send to renderer to apply audio changes
|
|
111
|
+
mainApp.sendToRenderer('mixer:toggleMasterMute', { bus, muted: newMuted });
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
success: true,
|
|
115
|
+
bus,
|
|
116
|
+
muted: newMuted,
|
|
117
|
+
};
|
|
118
|
+
} catch (error) {
|
|
119
|
+
console.error('Error toggling master mute:', error);
|
|
120
|
+
return {
|
|
121
|
+
success: false,
|
|
122
|
+
error: error.message,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Set master mute for a bus (explicit mute/unmute)
|
|
129
|
+
* @param {Object} mainApp - Main application instance
|
|
130
|
+
* @param {string} bus - Bus name (PA, IEM, or mic)
|
|
131
|
+
* @param {boolean} muted - Whether the bus should be muted
|
|
132
|
+
* @returns {Object} Result with success status
|
|
133
|
+
*/
|
|
134
|
+
export function setMasterMute(mainApp, bus, muted) {
|
|
135
|
+
try {
|
|
136
|
+
if (!bus || typeof muted !== 'boolean') {
|
|
137
|
+
return {
|
|
138
|
+
success: false,
|
|
139
|
+
error: 'bus (PA/IEM/mic) and muted status required',
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Update AppState immediately
|
|
144
|
+
const currentMixer = mainApp.appState.state.mixer;
|
|
145
|
+
if (currentMixer[bus]) {
|
|
146
|
+
// Create a new mixer state object with the updated bus
|
|
147
|
+
const updatedMixer = {
|
|
148
|
+
...currentMixer,
|
|
149
|
+
[bus]: {
|
|
150
|
+
...currentMixer[bus],
|
|
151
|
+
muted,
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
mainApp.appState.updateMixerState(updatedMixer);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Send to renderer to apply audio changes
|
|
158
|
+
mainApp.sendToRenderer('mixer:setMasterMute', { bus, muted });
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
success: true,
|
|
162
|
+
bus,
|
|
163
|
+
muted,
|
|
164
|
+
};
|
|
165
|
+
} catch (error) {
|
|
166
|
+
console.error('Error setting master mute:', error);
|
|
167
|
+
return {
|
|
168
|
+
success: false,
|
|
169
|
+
error: error.message,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
}
|