forked from
tokono.ma/diffuse
A music player that connects to your cloud/distributed storage.
1---
2layout: layouts/kitchen.vto
3base: ../
4title: Code | Diffuse
5
6examples:
7 - url: "facets/examples/now-playing/index.html"
8 title: "Now playing"
9 desc: >
10 Shows what's currently set to "now playing" in the queue, along with a button to shift the queue to the next track.
11 - url: "facets/examples/generate-playlist/index.html"
12 title: "Generate playlist"
13 desc: >
14 Make a list of what previously played in the queue.
15---
16
17<style>
18 h2 {
19 font-size: var(--fs-lg);
20 opacity: 0.6;
21 }
22</style>
23
24
25<h1 id="code" hidden>Code</h1>
26
27
28<!-- BUILD -->
29<section style="margin-top: var(--space-lg);">
30 <form id="code-form" class="columns">
31 <div class="flex" style="flex-basis: 35%">
32 <div id="html-input-container" class="code-editor monospace-font">
33 </div>
34 </div>
35
36 <div style="flex: 1; font-size: var(--fs-sm); max-width: var(--container-sm)">
37 <p style="margin-top: 0">
38 Your code here builds on the <a href="#foundation">foundation</a> listed below, and will be injected into a <span style="white-space: nowrap"><code><div id="container"></code></span> element in the body.
39 </p>
40 <p>
41 <input id="name-input" type="text" placeholder="Name" name="name" required />
42 </p>
43 <p>
44 <select id="kind-input" name="kind">
45 <option value="interactive" selected>Interactive</option>
46 <option value="prelude">Prelude</option>
47 </select>
48 </p>
49 <p>
50 <textarea id="description-input" placeholder="Description" name="description" rows="5"></textarea>
51 </p>
52 <p>
53 <span class="button-row">
54 <button class="button--bg-accent" name="save">Save</button>
55 <button class="button--bg-accent" name="save+open">Save & Open</button>
56 </span>
57 </p>
58 </div>
59 </form>
60</section>
61
62<!-- FOUNDATION -->
63<div class="columns">
64 <section class="flex">
65 <h2 id="foundation">Foundation</h2>
66
67 <p>
68 <strong>Diffuse comes with a foundation that preconfigures a lot of elements so you don't have to set them up yourself</strong>, along with a combination of elements for certain features. It internally tracks the DOM addition of the custom elements, so no need to worry about setting up an element multiple times. It also provides signals which can be used to track element creations. An example of this can be found in the "scrobbles" feature.
69 </p>
70 <p>
71 That said, you are not required not use this! You can, for example, setup a Diffuse audio engine element yourself that's in a different group so that it doesn't communicate with the default one; in case you want to make a dj-deck, or something like that, which would have multiple audio items playing at the same time. This does mean you will need to pay attention to more things, such as, how does this interact with other features the user has enabled.
72 </p>
73 <p>
74 <small><i class="ph-fill ph-info"></i> Refer to the <a href="elements/">elements index</a> to find out what each element does.</small>
75 </p>
76 <div class="code-block">
77 <code>
78 {{- echo -}}
79 import foundation from "common/foundation.js"
80 {{ /echo }}
81{{ echo -}}await foundation.configurator.artwork(){{- /echo }}
82{{ echo -}}await foundation.configurator.input(){{- /echo }}
83{{ echo -}}await foundation.configurator.metadata(){{- /echo }}
84{{ echo -}}await foundation.configurator.scrobbles(){{- /echo }}
85
86{{ echo -}}await foundation.engine.audio(){{- /echo }}
87{{ echo -}}await foundation.engine.queue(){{- /echo }}
88{{ echo -}}await foundation.engine.repeatShuffle(){{- /echo }}
89{{ echo -}}await foundation.engine.scope(){{- /echo }}
90
91{{ echo -}}await foundation.orchestrator.autoQueue(){{- /echo }}
92{{ echo -}}await foundation.orchestrator.favourites(){{- /echo }}
93{{ echo -}}await foundation.orchestrator.mediaSession(){{- /echo }}
94{{ echo -}}await foundation.orchestrator.output(){{- /echo }}
95{{ echo -}}await foundation.orchestrator.queueAudio(){{- /echo }}
96{{ echo -}}await foundation.orchestrator.processTracks(){{- /echo }}
97{{ echo -}}await foundation.orchestrator.scopedTracks(){{- /echo }}
98{{ echo -}}await foundation.orchestrator.scrobbleAudio(){{- /echo }}
99{{ echo -}}await foundation.orchestrator.sources(){{- /echo }}
100
101{{ echo -}}await foundation.orchestrator.artwork(){{- /echo -}}
102 </code>
103 </div>
104 </section>
105
106 <section class="flex">
107 <h2 id="examples">Examples</h2>
108
109 <p>
110 Some simple examples to help you understand how to build your own facet. Click the edit button to load them into the code editor above.
111 </p>
112
113 {{ await comp.examples({ id: "examples", items: examples }) }}
114
115 <h2 id="notes">Notes</h2>
116 <p>
117 While you have the ability to do whatever you want in a custom facet, the existing facets are designed to work a certain way; so here's some things to keep in mind:
118 </p>
119 <ul>
120 <li><span>Prelude (feature) facets are loaded in alphabetical order by the facet loader.</span></li>
121 <li><span>Most elements are configured in broadcast mode so they communicate across tabs. There are a few exceptions such as inputs, where we prefer parallelisation.</span></li>
122 <li><span>All URLs in a facet are relative to the root of Diffuse (not the root of the server) due to the base element in the header of the facet loader.</span></li>
123 </ul>
124 </section>
125</div>