diff --git a/apps.json b/apps.json index f6ac2f7f0..2f4e4067a 100644 --- a/apps.json +++ b/apps.json @@ -3034,7 +3034,7 @@ "name": "Gadgetbridge Music Controls", "shortName":"Music Controls", "icon": "icon.png", - "version":"0.01", + "version":"0.02", "description": "Control the music on your Gadgetbridge-connected phone", "tags": "tools,bluetooth,gadgetbridge,music", "type":"app", diff --git a/apps/gbmusic/ChangeLog b/apps/gbmusic/ChangeLog index ec66c5568..25a6f010c 100644 --- a/apps/gbmusic/ChangeLog +++ b/apps/gbmusic/ChangeLog @@ -1 +1,2 @@ 0.01: Initial version +0.02: Increase text brightness, try to improve memory usage \ No newline at end of file diff --git a/apps/gbmusic/app.js b/apps/gbmusic/app.js index a27f4daa7..f17d07e52 100644 --- a/apps/gbmusic/app.js +++ b/apps/gbmusic/app.js @@ -52,6 +52,7 @@ // Smaller interval+step might be smoother, but flickers :-( interval: 200, // scroll interval in ms step: 10, // scroll speed per interval + space: 40, // pixels between scrolling text }, artist: { // center below middle font: "Vector", @@ -163,10 +164,10 @@ this.since = null; } brightness() { - if (fadeOut.since) { - return Math.max(0, 1-((Date.now()-fadeOut.since)/TIMEOUT)); + if (!fadeOut.since) { + return 1; } - return 1; + return Math.max(0, 1-((Date.now()-fadeOut.since)/TIMEOUT)); } } @@ -183,27 +184,27 @@ } draw() { const s = defaults.track; - const sep = " "; g.setFont(s.font, s.size); g.setColor(infoColor("track")); - const text = sep+info.track, - text2 = text.repeat(2), - w1 = g.stringWidth(text), + const w = g.stringWidth(info.track)+s.space, bottom = screen.height-s.bottom; - this.offset = this.offset%w1; + this.offset = this.offset%w; g.setFontAlign(-1, 1); g.clearRect(0, bottom-s.size, screen.width, bottom) - .drawString(text2, -this.offset, screen.height-s.bottom); + .drawString(info.track, -this.offset+s.space, screen.height-s.bottom) + .drawString(info.track, -this.offset+s.space+w, screen.height-s.bottom); } start() { this.offset = 0; super.start(); } stop() { + if (this.active) { + const s = defaults.track, + bottom = screen.height-s.bottom; + g.clearRect(0, bottom-s.size, screen.width, bottom); + } super.stop(); - const s = defaults.track, - bottom = screen.height-s.bottom; - g.clearRect(0, bottom-s.size, screen.width, bottom); } } @@ -214,9 +215,9 @@ force: fadeOut.active, }, options)); } - let oldText = {}; + let oldText = {}, clear = {}; function drawText(name, text, options) { - if (name in oldText && oldText[name].text===text && !(options || {}).force) { + if (name in oldText && !(name in clear) && !(options || {}).force) { return; // nothing to do } const s = Object.assign( @@ -239,20 +240,16 @@ if (name in oldText) { const old = oldText[name]; // only clear if text/area has changed - if (old.text!==text - || old.left!==left || old.top!==top - || old.w!==w || old.h!==h) { - g.clearRect(old.left, old.top, old.left+old.w, old.top+old.h); + if (name in clear || [left, top, w, h].toString()!==old.toString()) { + // left top left+w left+h + g.clearRect(old[0], old[1], old[0]+old[2], old[1]+old[3]); } } + delete clear[name]; if (text.length) { g.drawString(text, x, y); // remember which rectangle to clear before next draw - oldText[name] = { - text: text, - left: left, top: top, - w: w, h: h, - }; + oldText[name] = [left, top, w, h]; } else { delete oldText[name]; } @@ -306,6 +303,9 @@ */ let infoColors = {}; function infoColor(name) { + if (name in infoColors && !fadeOut.active) { + return infoColors[name]; + } let h, s, v; if (name==="num") { // always white @@ -313,31 +313,29 @@ s = 0; } else { // complicated scheme to make color depend deterministically on info - // s=1 and hue depends on the text, so we always get a bright color - let text = ""; + let code = 0; + const textCode = t => { + let c = 0; + for(let i = 0; i code += c.charCodeAt(0)); - // dark magic h = code%360; - s = 1; + s = 0.7; } v = fadeOut.brightness(); + // dark magic const hsv2rgb = (h, s, v) => { const f = (n) => { const k = (n+h/60)%6; @@ -352,21 +350,19 @@ return color; } - let lastTrack; function drawTrack() { // we try if we can squeeze this in with a slightly smaller font, but if // the title is too long we start up the scroller instead - const trackInfo = ([info.artist, info.album, info.n, info.track]).join("-"); - if (trackInfo===lastTrack) { - return; // already visible - } if (infoSize("track")