Mercurial > code > home > repos > light9
annotate web/light9-music.coffee @ 2376:4556eebe5d73
topdir reorgs; let pdm have its src/ dir; separate vite area from light9/
author | drewp@bigasterisk.com |
---|---|
date | Sun, 12 May 2024 19:02:10 -0700 |
parents | light9/web/light9-music.coffee@e29315086f9f |
children |
rev | line source |
---|---|
1901
7fe81130b735
move web logging to https://github.com/visionmedia/debug/ so it can have channels that can be turned off
Drew Perttula <drewp@bigasterisk.com>
parents:
1731
diff
changeset
|
1 log = debug('music') |
1335 | 2 |
3 # port of light9/curvecalc/musicaccess.py | |
1731
e06c2c105035
workaround for coffee issue with static getters. polymer wasn't seeing my attributes at all
Drew Perttula <drewp@bigasterisk.com>
parents:
1339
diff
changeset
|
4 coffeeElementSetup(class Music extends Polymer.Element |
e06c2c105035
workaround for coffee issue with static getters. polymer wasn't seeing my attributes at all
Drew Perttula <drewp@bigasterisk.com>
parents:
1339
diff
changeset
|
5 @is: "light9-music", |
e06c2c105035
workaround for coffee issue with static getters. polymer wasn't seeing my attributes at all
Drew Perttula <drewp@bigasterisk.com>
parents:
1339
diff
changeset
|
6 @getter_properties: |
1335 | 7 status: { type: String, notify: true } |
1336 | 8 statusTitle: { type: String, notify: true } |
9 turboSign: { type: String, notify: true } | |
10 | |
1335 | 11 duration: { type: Number, notify: true } |
1338
5ba5afe30817
ctrl-p does seekPlayOrPause
Drew Perttula <drewp@bigasterisk.com>
parents:
1336
diff
changeset
|
12 song: { type: String, notify: true } |
5ba5afe30817
ctrl-p does seekPlayOrPause
Drew Perttula <drewp@bigasterisk.com>
parents:
1336
diff
changeset
|
13 # It does not yet work to write back to the playing/t |
5ba5afe30817
ctrl-p does seekPlayOrPause
Drew Perttula <drewp@bigasterisk.com>
parents:
1336
diff
changeset
|
14 # properties. See seekPlayOrPause. |
1335 | 15 playing: { type: Boolean, notify: true } |
16 t: { type: Number, notify: true } | |
1336 | 17 |
1335 | 18 ready: -> |
1731
e06c2c105035
workaround for coffee issue with static getters. polymer wasn't seeing my attributes at all
Drew Perttula <drewp@bigasterisk.com>
parents:
1339
diff
changeset
|
19 super.ready() |
1336 | 20 @turboUntil = 0 |
1335 | 21 @poll() |
1339
f24d4b331f15
zoom keys, with animation. timeline duration tracks ascoltami
Drew Perttula <drewp@bigasterisk.com>
parents:
1338
diff
changeset
|
22 setInterval(@estimateTimeLoop.bind(@), 30) |
1731
e06c2c105035
workaround for coffee issue with static getters. polymer wasn't seeing my attributes at all
Drew Perttula <drewp@bigasterisk.com>
parents:
1339
diff
changeset
|
23 |
e06c2c105035
workaround for coffee issue with static getters. polymer wasn't seeing my attributes at all
Drew Perttula <drewp@bigasterisk.com>
parents:
1339
diff
changeset
|
24 onError: (e) -> |
e06c2c105035
workaround for coffee issue with static getters. polymer wasn't seeing my attributes at all
Drew Perttula <drewp@bigasterisk.com>
parents:
1339
diff
changeset
|
25 req = @$.getTime.lastRequest |
e06c2c105035
workaround for coffee issue with static getters. polymer wasn't seeing my attributes at all
Drew Perttula <drewp@bigasterisk.com>
parents:
1339
diff
changeset
|
26 @status = "✘" |
e06c2c105035
workaround for coffee issue with static getters. polymer wasn't seeing my attributes at all
Drew Perttula <drewp@bigasterisk.com>
parents:
1339
diff
changeset
|
27 @statusTitle = "GET "+req.url+ " -> " + req.status + " " + req.statusText |
e06c2c105035
workaround for coffee issue with static getters. polymer wasn't seeing my attributes at all
Drew Perttula <drewp@bigasterisk.com>
parents:
1339
diff
changeset
|
28 setTimeout(@poll.bind(@), 2000) |
1338
5ba5afe30817
ctrl-p does seekPlayOrPause
Drew Perttula <drewp@bigasterisk.com>
parents:
1336
diff
changeset
|
29 |
1336 | 30 estimateTimeLoop: -> |
31 if @playing | |
32 @t = @remoteT + (Date.now() - @remoteAsOfMs) / 1000 | |
33 else | |
34 @t = @remoteT | |
35 | |
1335 | 36 poll: -> |
1731
e06c2c105035
workaround for coffee issue with static getters. polymer wasn't seeing my attributes at all
Drew Perttula <drewp@bigasterisk.com>
parents:
1339
diff
changeset
|
37 if not @$?.getTime? |
e06c2c105035
workaround for coffee issue with static getters. polymer wasn't seeing my attributes at all
Drew Perttula <drewp@bigasterisk.com>
parents:
1339
diff
changeset
|
38 setTimeout(@poll.bind(@), 200) |
e06c2c105035
workaround for coffee issue with static getters. polymer wasn't seeing my attributes at all
Drew Perttula <drewp@bigasterisk.com>
parents:
1339
diff
changeset
|
39 return |
1338
5ba5afe30817
ctrl-p does seekPlayOrPause
Drew Perttula <drewp@bigasterisk.com>
parents:
1336
diff
changeset
|
40 clearTimeout(@nextPoll) if @nextPoll |
1335 | 41 @$.getTime.generateRequest() |
1336 | 42 @status = "♫" |
1338
5ba5afe30817
ctrl-p does seekPlayOrPause
Drew Perttula <drewp@bigasterisk.com>
parents:
1336
diff
changeset
|
43 |
1335 | 44 onResponse: -> |
1336 | 45 @status = " " |
1338
5ba5afe30817
ctrl-p does seekPlayOrPause
Drew Perttula <drewp@bigasterisk.com>
parents:
1336
diff
changeset
|
46 @lastResponse = @$.getTime.lastResponse |
1336 | 47 now = Date.now() |
1338
5ba5afe30817
ctrl-p does seekPlayOrPause
Drew Perttula <drewp@bigasterisk.com>
parents:
1336
diff
changeset
|
48 if !@lastResponse.playing && @lastResponse.t != @remoteT |
1336 | 49 # likely seeking in another tool |
50 @turboUntil = now + 1000 | |
51 if now < @turboUntil | |
52 @turboSign = "⚡" | |
53 delay = 20 | |
54 else | |
55 @turboSign = " " | |
56 delay = 700 | |
57 | |
1338
5ba5afe30817
ctrl-p does seekPlayOrPause
Drew Perttula <drewp@bigasterisk.com>
parents:
1336
diff
changeset
|
58 @nextPoll = setTimeout(@poll.bind(@), delay) |
5ba5afe30817
ctrl-p does seekPlayOrPause
Drew Perttula <drewp@bigasterisk.com>
parents:
1336
diff
changeset
|
59 @duration = @lastResponse.duration |
5ba5afe30817
ctrl-p does seekPlayOrPause
Drew Perttula <drewp@bigasterisk.com>
parents:
1336
diff
changeset
|
60 @playing = @lastResponse.playing |
5ba5afe30817
ctrl-p does seekPlayOrPause
Drew Perttula <drewp@bigasterisk.com>
parents:
1336
diff
changeset
|
61 @song = @lastResponse.song |
1336 | 62 |
1338
5ba5afe30817
ctrl-p does seekPlayOrPause
Drew Perttula <drewp@bigasterisk.com>
parents:
1336
diff
changeset
|
63 @remoteT = @lastResponse.t |
1336 | 64 @remoteAsOfMs = now |
65 | |
1338
5ba5afe30817
ctrl-p does seekPlayOrPause
Drew Perttula <drewp@bigasterisk.com>
parents:
1336
diff
changeset
|
66 seekPlayOrPause: (t) -> |
5ba5afe30817
ctrl-p does seekPlayOrPause
Drew Perttula <drewp@bigasterisk.com>
parents:
1336
diff
changeset
|
67 @$.seek.body = {t: t} |
5ba5afe30817
ctrl-p does seekPlayOrPause
Drew Perttula <drewp@bigasterisk.com>
parents:
1336
diff
changeset
|
68 @$.seek.generateRequest() |
1336 | 69 |
1338
5ba5afe30817
ctrl-p does seekPlayOrPause
Drew Perttula <drewp@bigasterisk.com>
parents:
1336
diff
changeset
|
70 @turboUntil = Date.now() + 1000 |
5ba5afe30817
ctrl-p does seekPlayOrPause
Drew Perttula <drewp@bigasterisk.com>
parents:
1336
diff
changeset
|
71 @poll() |
1731
e06c2c105035
workaround for coffee issue with static getters. polymer wasn't seeing my attributes at all
Drew Perttula <drewp@bigasterisk.com>
parents:
1339
diff
changeset
|
72 ) |
e06c2c105035
workaround for coffee issue with static getters. polymer wasn't seeing my attributes at all
Drew Perttula <drewp@bigasterisk.com>
parents:
1339
diff
changeset
|
73 |