This commit is contained in:
Djkato 2023-07-20 17:28:22 +02:00
parent 8ae616d1c7
commit 84fb83480a
5 changed files with 28 additions and 13 deletions

View file

@ -1,6 +1,6 @@
{
"name": "@euterpe.js/euterpe",
"version": "1.0.4",
"version": "1.0.5",
"type": "module",
"description": "Fully featured solution for playing music on the web. Support for local library, audio visuals and more!",
"main": "./src/index.js",

View file

@ -1,6 +1,6 @@
{
"name": "@euterpe.js/music-library",
"version": "1.0.7",
"version": "1.0.8",
"type": "module",
"description": "A simple music library, acting as a Local DB as JS Object. Contains everything a person would need to store their music data for website playback.",
"main": "./src/index.js",

View file

@ -47,7 +47,7 @@ class Ref {
return from.songs.find((song) => song.id == this.id)
}
case RefTo.Collections: {
return from.collections.find((col) => col.id = this.id)
return from.collections.find((col) => col.id == this.id)
}
}
}
@ -195,7 +195,6 @@ class DB {
if (input instanceof Artist) {
const artist = input as Artist
if (!artist.id) artist.id = this.artists.length
this.artists.push(artist)
for (const song_ref of artist.songs) {
const curr_song = song_ref.get(this) as Song
@ -206,12 +205,12 @@ class DB {
const curr_col = col_ref.get(this) as Collection
curr_col?.artists.push(new Ref(RefTo.Artists, artist.id))
}
this.artists.push(artist)
}
else if (input instanceof Collection) {
const col = input as Collection
if (!col.id) col.id = this.collections.length
this.collections.push(col)
for (const song_ref of col.songs) {
const curr_song = song_ref.get(this) as Song
@ -221,22 +220,30 @@ class DB {
const curr_artist = artist_ref.get(this) as Artist
curr_artist.collections.push(new Ref(RefTo.Collections, col.id))
}
this.collections.push(col)
}
else if (input instanceof Song) {
const song = input as Song
if (!song.id) song.id = this.songs.length
this.songs.push(song)
if (song.in_collection) {
const curr_col = song.in_collection.get(this) as Collection
curr_col?.songs.push(new Ref(RefTo.Songs, song.id))
curr_col.songs.push(new Ref(RefTo.Songs, song.id))
song.artists.forEach((artist) => curr_col.artists.push(new Ref(RefTo.Artists, artist.get(this)!.id!)))
song.remix_artists.forEach((artist) => curr_col.artists.push(new Ref(RefTo.Artists, artist.get(this)!.id!)))
}
for (const artist_ref of song.artists) {
const curr_artist = artist_ref.get(this) as Artist
curr_artist.songs.push(new Ref(RefTo.Songs, song.id))
}
for (const artist_ref of song.remix_artists) {
const curr_artist = artist_ref.get(this) as Artist
curr_artist.songs.push(new Ref(RefTo.Songs, song.id))
}
this.songs.push(song)
}
}
this.songs.sort((a, b) => a.id! - b.id!)

View file

@ -26,9 +26,10 @@ export function generate_db() {
})])
collections.push(collection_name)
}
let col = db.collections.find(col => col.name == collection_name)!
let col_id = col.id
new_songs.push({ song: song, collection_id: col_id })
new_songs.push({ song: song, collection_id: col_id! })
}
//create songs
@ -38,14 +39,13 @@ export function generate_db() {
const name = song.song.slice(last_i + 1)
const song_url = song.song.replace("\\\\", "/").slice(7)
const db_song = new Song({
name: name.slice(0, name.lastIndexOf(".")),
artists: [],
url: new URL("http://localhost:4200/" + song_url),
duration: 0,
remix_artists: [],
in_collection: new Ref(RefTo.Collections, song.collection_id!)
in_collection: new Ref(RefTo.Collections, song.collection_id)
})
db.add([db_song])
}

View file

@ -6,7 +6,6 @@ document.getElementById("button")!.addEventListener("click", (ev) => {
start()
})
export async function start() {
generate_db()
analyze().then(async (result) => {
console.log("Creating svgs...")
const waveform_canvas = document.querySelector("#waveform-canvas") as SVGSVGElement
@ -24,7 +23,7 @@ export async function start() {
song.fft_data = []
}
console.dir(result.db, { depth: null })
console.log(JSON.stringify(result.db))
download(JSON.stringify(result.db), "db.json", "text/plain")
})
}
async function analyze(): Promise<AnalyzeReturn> {
@ -46,6 +45,7 @@ async function analyze(): Promise<AnalyzeReturn> {
track.connect(audioContextAnalyser).connect(gain).connect(audioContext.destination)
let db = generate_db()
console.log(db)
for (const song of db.songs) {
// const song = db.songs[db.songs.length - 1]
console.log(`Analyzing ${song.name}, ${db.songs.indexOf(song) + 1}/${db.songs.length}`)
@ -72,6 +72,14 @@ async function analyze(): Promise<AnalyzeReturn> {
const result: AnalyzeReturn = { analyzer_node: audioContextAnalyser, db: db }
return result
}
function download(content: BlobPart, fileName: string, contentType: string) {
var a = document.createElement("a");
var file = new Blob([content], { type: contentType });
a.href = URL.createObjectURL(file);
a.download = fileName;
a.click();
}
type AnalyzeReturn = {
analyzer_node: AnalyserNode,
db: DB