Created
March 2, 2022 09:34
-
-
Save FunctionDJ/914b3066d1ab368c1fd1a62b4e13f55f to your computer and use it in GitHub Desktop.
marc2k3's spectrogram edited
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict" | |
window.DefineScript("Spectrogram Edit") | |
include("./felpers.js") | |
const ffmpegFilterConfig = "atrim=0:30,showspectrumpic=legend=0:s=512x512" | |
const titleFormatImagePath = fb.TitleFormat(`$crc32($lower(%path%'${ffmpegFilterConfig}')).jpeg`) | |
const titleFormatCue = fb.TitleFormat("$if($or($strcmp(%__cue_embedded%,yes),$strcmp($right(%path%,3),cue)),cue,)") | |
const dataFolder = pathJoin(fb.ProfilePath, "js_data") | |
idemptCreateFolder(dataFolder) | |
const cacheFolder = pathJoin(dataFolder, "spectrogram_cache") | |
idemptCreateFolder(cacheFolder) | |
/** @type {GdiBitmap|string} */ | |
let content = "Idle" | |
const update = () => { | |
const metaDB = fb.GetNowPlaying() | |
if ( | |
metaDB === null | |
|| !metaDB.RawPath.includes("file") | |
|| titleFormatCue.Eval() === "cue" | |
|| metaDB.SubSong > 0 | |
) { | |
console.log("The horsemen") | |
return null | |
} | |
const filepath = pathJoin(cacheFolder, titleFormatImagePath.Eval()) | |
const isCached = utils.IsFile(filepath) | |
if (isCached) { | |
updateSpectogram(filepath) | |
return | |
} | |
updateSpectogram(null) | |
const cmd = `ffmpeg -i "${metaDB.Path}" -lavfi ${ffmpegFilterConfig} "${filepath}"` | |
console.log(cmd) | |
runSync(cmd) | |
updateSpectogram(filepath) | |
} | |
/** @param {string|null} imgPath */ | |
const updateSpectogram = imgPath => { | |
if (imgPath === null) { | |
content = "Loading..." | |
} else { | |
const img = gdi.Image(imgPath) | |
content = img || "Unable to load image" | |
} | |
window.Repaint() | |
} | |
if (fb.IsPlaying) { | |
update() | |
} | |
function on_playback_new_track() { | |
update() | |
} | |
const font = gdi.Font("Helvetica Neue LT Pro", 16) | |
/** @param {GdiGraphics} gr */ | |
function on_paint(gr) { | |
gr.FillSolidRect(0, 0, window.Width, window.Height, rgb(0, 0, 0)) | |
if (font === null) { | |
throw new Error("couldn't load font") | |
} | |
if (typeof content === "object") { | |
drawImage(gr, content, 0, 0, window.Width, window.Height, "stretch") | |
} else { | |
gr.DrawString(content, font, rgb(100, 100, 100), 20, 20, 100, 50) | |
} | |
} | |
/** | |
* @param {number} x | |
* @param {number} y | |
*/ | |
function on_mouse_rbtn_up(x, y) { | |
const menu = window.CreatePopupMenu() | |
menu.AppendMenuItem(MF_STRING, 5, "Configure...") | |
const idx = menu.TrackPopupMenu(x, y) | |
if (idx === 5) { | |
window.ShowConfigureV2() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment