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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
3843f6bd0460 music time fetcher
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
2
3843f6bd0460 music time fetcher
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
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
3843f6bd0460 music time fetcher
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
7 status: { type: String, notify: true }
1336
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
8 statusTitle: { type: String, notify: true }
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
9 turboSign: { type: String, notify: true }
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
10
1335
3843f6bd0460 music time fetcher
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
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
3843f6bd0460 music time fetcher
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
15 playing: { type: Boolean, notify: true }
3843f6bd0460 music time fetcher
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
16 t: { type: Number, notify: true }
1336
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
17
1335
3843f6bd0460 music time fetcher
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
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
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
20 @turboUntil = 0
1335
3843f6bd0460 music time fetcher
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
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
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
30 estimateTimeLoop: ->
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
31 if @playing
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
32 @t = @remoteT + (Date.now() - @remoteAsOfMs) / 1000
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
33 else
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
34 @t = @remoteT
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
35
1335
3843f6bd0460 music time fetcher
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
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
3843f6bd0460 music time fetcher
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
41 @$.getTime.generateRequest()
1336
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
42 @status = "♫"
1338
5ba5afe30817 ctrl-p does seekPlayOrPause
Drew Perttula <drewp@bigasterisk.com>
parents: 1336
diff changeset
43
1335
3843f6bd0460 music time fetcher
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
44 onResponse: ->
1336
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
45 @status = " "
1338
5ba5afe30817 ctrl-p does seekPlayOrPause
Drew Perttula <drewp@bigasterisk.com>
parents: 1336
diff changeset
46 @lastResponse = @$.getTime.lastResponse
1336
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
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
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
49 # likely seeking in another tool
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
50 @turboUntil = now + 1000
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
51 if now < @turboUntil
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
52 @turboSign = "⚡"
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
53 delay = 20
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
54 else
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
55 @turboSign = " "
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
56 delay = 700
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
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
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
62
1338
5ba5afe30817 ctrl-p does seekPlayOrPause
Drew Perttula <drewp@bigasterisk.com>
parents: 1336
diff changeset
63 @remoteT = @lastResponse.t
1336
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
64 @remoteAsOfMs = now
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
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
2d77dc9436c3 music drives cursor
Drew Perttula <drewp@bigasterisk.com>
parents: 1335
diff changeset
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