@@ -4,7 +4,7 @@ import frag0 from './renderpasses/renderpass0/frag.js';
44import vert from './renderpasses/renderpass0/vert.js' ;
55import * as dat from 'datgui' ;
66import { Dexie } from 'https://unpkg.com/dexie/dist/modern/dexie.mjs' ;
7- import { countImageColors , readTags , strToCodes } from './utils.js' ;
7+ import { countImageColors , loadImage , readTags , sprite , strToCodes , strToImage } from './utils.js' ;
88
99/**
1010 * @type {Points }
@@ -47,17 +47,21 @@ function clickSong() {
4747 playSong ( this ) ;
4848}
4949
50- function playSong ( song ) {
50+ async function playSong ( song ) {
5151 const { file } = song ;
5252 points . setUniform ( 'showMessage' , 0 ) ;
5353 const audioUrl = URL . createObjectURL ( file ) ;
5454 const name = song ?. name || file . name ;
55- const title = song ?. title || name ;
55+ const title = name ;
5656
5757 audio && audio . pause ( ) && ( audio = null ) ;
5858 audio = points . setAudio ( 'audio' , audioUrl , options . volume , false , false ) ;
5959 points . setUniform ( 'numChars' , title . length < MAXCHARS ? title . length : MAXCHARS ) ;
60- points . setStorageMap ( 'chars' , strToCodes ( title ) ) ;
60+ // points.setStorageMap('chars', strToCodes(title));
61+
62+ const songNameImg = strToImage ( title , atlas , size ) ;
63+ await points . setTextureImage ( 'songName' , songNameImg ) ;
64+
6165 let artworkLoaded = 0 ;
6266 song ?. artworkColors && points . setStorageMap ( 'artworkColors' , song ?. artworkColors . flat ( ) ) ;
6367 song ?. artworkColors && ( artworkLoaded = 1 ) ;
@@ -129,7 +133,8 @@ async function onCompleteTags(result) {
129133 const { tag, song } = result ;
130134 const { file } = song ;
131135 const { title, album, picture } = tag . tags ;
132- const name = `${ title } - ${ album } `
136+ const albumExists = album ?` - ${ album } ` : '' ;
137+ const name = `${ title } ${ albumExists } `
133138 let artworkImageUrl = null ;
134139 let artworkColors = null ;
135140
@@ -147,7 +152,7 @@ async function onCompleteTags(result) {
147152 }
148153
149154 song . name = name || file . name ;
150- song . title = title || name ;
155+ song . title = name ;
151156
152157
153158 if ( ! song . default ) {
@@ -162,7 +167,10 @@ async function onCompleteTags(result) {
162167
163168 folderSongs . add ( song , 'fn' ) . name ( song . name ) ;
164169 points . setUniform ( 'numChars' , title . length < MAXCHARS ? title . length : MAXCHARS ) ;
165- points . setStorageMap ( 'chars' , strToCodes ( title ) ) ;
170+ // points.setStorageMap('chars', strToCodes(title));
171+
172+ const songNameImg = strToImage ( title , atlas , size ) ;
173+ await points . setTextureImage ( 'songName' , songNameImg ) ;
166174}
167175
168176async function onErrorTags ( response ) {
@@ -333,11 +341,24 @@ points.setUniform('progress', 0);
333341points . setUniform ( 'artworkLoaded' , 0 ) ;
334342// points.setUniform('somecolor', colors.color2, 'vec3f');
335343points . setUniform ( 'numChars' , 12 ) ;
336- points . setStorageMap ( 'chars' , strToCodes ( 'Gravity Pull' ) , 'array<f32>' ) // TODO: setStorageMap doesn't work with u32 wrong sized
337- points . setStorageMap ( 'message' , strToCodes ( 'Select a song to Play' ) , 'array<f32>' ) // TODO: setStorageMap doesn't work with u32 wrong sized
344+ // points.setStorageMap('chars', strToCodes('Gravity Pull'), 'array<f32>')// TODO: setStorageMap doesn't work with u32 wrong sized
338345points . setStorageMap ( 'artworkColors' , Array ( 16 ) . fill ( 1 ) , 'array<vec4f>' ) ;
339346points . setStorage ( 'variables' , 'Variables' ) ;
340347await points . setTextureImage ( 'font' , './src/img/inconsolata_regular_8x22.png' ) ;
348+
349+
350+
351+ const size = { x : 8 , y : 22 } ;
352+ const atlas = await loadImage ( 'src/img/inconsolata_regular_8x22.png' ) ;
353+ const messageStringImg = strToImage ( 'Select a song to Play' , atlas , size ) ;
354+ await points . setTextureImage ( 'messageString' , messageStringImg ) ;
355+
356+
357+
358+ const songNameImg = strToImage ( 'Gravity Pull' , atlas , size ) ;
359+ await points . setTextureImage ( 'songName' , songNameImg ) ;
360+
361+
341362const renderPasses = [
342363 new RenderPass ( vert , frag0 , null ) ,
343364] ;
@@ -432,4 +453,4 @@ async function loadSongFromURL() {
432453 window . history . replaceState ( null , '' , url . toString ( ) ) ;
433454}
434455
435- loadSongFromURL ( )
456+ loadSongFromURL ( )
0 commit comments