Skip to content

Commit 025f9e7

Browse files
committed
Improve docs and fix bug with specifying window size when not using Milkdrop
1 parent 946b57a commit 025f9e7

File tree

10 files changed

+219
-80
lines changed

10 files changed

+219
-80
lines changed

examples/minimalMilkdrop/index.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<script src="https://unpkg.com/[email protected]/lib/butterchurnPresets.min.js"></script>
1414
<script>
1515
const Webamp = window.Webamp;
16-
new Webamp({
16+
const webamp = new Webamp({
1717
initialTracks: [
1818
{
1919
metaData: {
@@ -46,7 +46,8 @@
4646
playlist: { position: { x: 0, y: 232 }, size: [0, 4] },
4747
milkdrop: { position: { x: 275, y: 0 }, size: [7, 12] },
4848
},
49-
}).renderWhenReady(document.getElementById("app"));
49+
});
50+
webamp.renderWhenReady(document.getElementById("app"));
5051
</script>
5152
</body>
5253
</html>
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Minimal Example Window Layout
2+
3+
This example demonstrates configuring the initial layout of windows in Webamp.
4+
5+
You should be able to open this local html file in your browser and see Webamp working.
6+
7+
```
8+
$ git clone [email protected]:captbaritone/webamp.git
9+
$ cd webamp
10+
$ open examples/minimalWindowLayout/index.html
11+
```
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
</head>
6+
7+
<body>
8+
<div id="app" style="height: 100vh">
9+
<!-- Webamp will attempt to center itself within this div -->
10+
</div>
11+
<script src="https://unpkg.com/[email protected]/built/webamp.bundle.min.js"></script>
12+
<script>
13+
const Webamp = window.Webamp;
14+
const webamp = new Webamp({
15+
windowLayout: {
16+
main: {
17+
position: { top: 0, left: 0 },
18+
shadeMode: true,
19+
closed: false,
20+
},
21+
equalizer: {
22+
position: { top: 230, left: 0 },
23+
shadeMode: true,
24+
closed: false,
25+
},
26+
playlist: {
27+
position: { top: 28, left: 0 },
28+
shadeMode: false,
29+
size: { extraHeight: 3, extraWidth: 11 },
30+
closed: false,
31+
},
32+
},
33+
enableDoubleSizeMode: true,
34+
});
35+
36+
// Returns a promise indicating when it's done loading.
37+
webamp.renderWhenReady(document.getElementById("app"));
38+
</script>
39+
</body>
40+
</html>

examples/readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This directory contains a number of examples of how to add Webamp to a project.
55
- [Minimal](./minimal) Stick Webamp in a `<script>` tag, and add a few lines of JavaScript to get Webamp on your page.
66
- [Multiple Tracks](./multipleTracks) An example of setting up Webamp with multiple audio tracks.
77
- [Multiple Skins](./multipleSkins) An example of setting up Webamp with multiple skins.
8+
- [Minimal Window Layout](./minimalWindowLayout) An example of configuring the initial layout of windows in Webamp.
89
- [Webpack](./webpack) Install Webamp via NPM and bundle it in a Webpack bundle.
910
- [Webpack Lazyload](./webpackLazyLoad) **In progress**
1011
- [Minimal Milkdrop](./minimalMilkdrop) **In progress**

examples/webpackLazyLoad/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Webamp from "webamp";
22

3-
new Webamp({
3+
const webamp = new Webamp({
44
initialTracks: [
55
{
66
metaData: {
@@ -40,4 +40,6 @@ new Webamp({
4040
playlist: { position: { x: 0, y: 232 }, size: [0, 4] },
4141
milkdrop: { position: { x: 275, y: 0 }, size: [7, 12] },
4242
},
43-
}).renderWhenReady(document.getElementById("app"));
43+
});
44+
45+
webamp.renderWhenReady(document.getElementById("app"));

packages/webamp/CHANGELOG.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
### Features
44

55
- Allow a single mouse drag across the EQ to set all values [#1180](https://github.com/captbaritone/webamp/pull/1180)
6-
- Configure the initial layout of windows -- size, position, openness, shade mode -- when constructing a Webamp instance.
7-
- Configure if "double size mode" should be enabled when constructing a Webamp instance.
6+
- Configure the initial layout of windows -- size, position, openness, shade mode -- when constructing a Webamp instance. See `windowLayout` in the [Usage](./docs/usage.md) docs for more information.
7+
- Configure if "double size mode" should be enabled when constructing a Webamp instance. See `enableDoubleSizeMode` in the [Usage](./docs/usage.md) docs for more information.
88
- Optically allow users to lazily load heavy dependencies like JSZip and music-metadata-browser with the `webamp/lazy` entry point.
9+
- Include source maps for non-minified bundles.
10+
11+
### Bug Fixes
12+
13+
- Fix bug where track position slider could get stuck on mobile. [PR](https://github.com/captbaritone/webamp/pull/1253)
914

1015
### Internal Improvements:
1116

packages/webamp/demo/js/webampConfig.ts

+20-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export async function getWebampConfig(
6767
if (isButterchurnSupported()) {
6868
const startWithMilkdropHidden = skinUrl != null || screenshot;
6969

70-
__butterchurnOptions = getButterchurnOptions(startWithMilkdropHidden);
70+
__butterchurnOptions = undefined; // getButterchurnOptions(startWithMilkdropHidden);
7171

7272
if (
7373
startWithMilkdropHidden ||
@@ -112,7 +112,25 @@ export async function getWebampConfig(
112112
? SoundCloud.tracksFromPlaylist(soundCloudPlaylist)
113113
: initialTracks,
114114
availableSkins,
115-
windowLayout,
115+
windowLayout: {
116+
main: {
117+
position: { top: 0, left: 0 },
118+
shadeMode: true,
119+
closed: false,
120+
},
121+
equalizer: {
122+
position: { top: 230, left: 0 },
123+
shadeMode: true,
124+
closed: false,
125+
},
126+
playlist: {
127+
position: { top: 28, left: 0 },
128+
shadeMode: false,
129+
size: { extraHeight: 3, extraWidth: 11 },
130+
closed: false,
131+
},
132+
},
133+
enableDoubleSizeMode: true,
116134
filePickers: [dropboxFilePicker],
117135
enableHotkeys: true,
118136
handleTrackDropEvent: (e) => {

packages/webamp/docs/usage.md

+113-65
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ Here's how to use Webamp in your own project. If you get stuck, or need help, pl
44

55
## Examples
66

7-
If you would like to look at some examples check out the [examples directory](../examples/) where you will find:
7+
If you would like to look at some examples check out the [examples directory](../../../examples/) where you will find:
88

9-
- [Minimal](../examples/minimal/) - An example that just uses a `<script>` tag that points to a CDN. No install required.
10-
- [Webpack](../examples/webpack/) - An example that installs Webamp via NPM, and bundles it into an application using Webpack.
9+
- [Minimal](../../../examples/minimal) Stick Webamp in a `<script>` tag, and add a few lines of JavaScript to get Webamp on your page.
10+
- [Multiple Tracks](../../../examples/multipleTracks) An example of setting up Webamp with multiple audio tracks.
11+
- [Multiple Skins](../../../examples/multipleSkins) An example of setting up Webamp with multiple skins.
12+
- [Minimal Window Layout](../../../examples/minimalWindowLayout) An example of configuring the initial layout of windows in Webamp.
13+
- [Webpack](../../../examples/webpack) Install Webamp via NPM and bundle it in a Webpack bundle.
14+
- [Webpack Lazyload](../../../examples/webpackLazyLoad) **In progress**
15+
- [Minimal Milkdrop](../../../examples/minimalMilkdrop) **In progress**
1116

1217
Each example has a README which explains it in more detail.
1318

@@ -128,75 +133,118 @@ if(Winamp.browserIsSupported()) {
128133

129134
The `Winamp` class is constructed with an options object. All are optional.
130135

131-
```JavaScript
136+
```ts
132137
const options = {
133-
// Optional. An object representing the initial skin to use.
134-
// If omitted, the default skin, included in the bundle, will be used.
135-
// Note: This URL must be served the with correct CORs headers.
136-
initialSkin: {
137-
url: './path/to/skin.wsz'
138-
},
138+
// Optional. An object representing the initial skin to use.
139+
// If omitted, the default skin, included in the bundle, will be used.
140+
// Note: This URL must be served the with correct CORs headers.
141+
initialSkin: {
142+
url: "./path/to/skin.wsz",
143+
},
139144

140-
// Optional. An array of `track`s (see above) to prepopulate the playlist with.
141-
initialTracks: [/* ... */],
142-
143-
// Optional. An array of objects representing skins.
144-
// These will appear in the "Options" menu under "Skins".
145-
// Note: These URLs must be served with the correct CORs headers.
146-
availableSkins: [
147-
{ url: "./green.wsz", name: "Green Dimension V2" },
148-
{ url: "./osx.wsz", name: "Mac OSX v1.5 (Aqua)" }
149-
],
150-
151-
// Optional. (Default: `false`) Should double size mode be enabled?
152-
enableDoubleSizeMode: true,
153-
154-
// Optional. (Default: `false`) Should global hotkeys be enabled?
155-
enableHotkeys: true,
156-
157-
// Optional. (Default: `0`) The zIndex that Webamp should use.
158-
zIndex: 99999,
159-
160-
// Optional. An array of additional file pickers.
161-
// These will appear in the "Options" menu under "Play".
162-
// In the demo site, This option is used to provide a "Dropbox" file
163-
// picker.
164-
filePickers: [{
165-
// The name that will appear in the context menu.
166-
contextMenuName: "My File Picker...",
167-
// A function which returns a Promise that resolves to
168-
// an array of `track`s (see above)
169-
filePicker: () => Promise.resolve([{
170-
url: './rick_roll.mp3'
171-
}]),
172-
// A boolean indicating if this options should be made
173-
// available when the user is offline.
174-
requiresNetwork: true
175-
}],
176-
177-
// Optional. Provide a custom way to derive `Track` objects from a drop event.
178-
// Useful if your website has some DOM representation of a track that you can map to a URL/blob.
179-
handleTrackDropEvent: async (e) => {
180-
// Return an array of `Track` objects, see documentation below, or `null` to get the default drop behavior.
181-
// You may optionally wrap the return value in a promise.
182-
},
145+
// Optional. An array of `track`s (see above) to prepopulate the playlist with.
146+
initialTracks: [
147+
/* ... */
148+
],
149+
150+
// Optional. An array of objects representing skins.
151+
// These will appear in the "Options" menu under "Skins".
152+
// Note: These URLs must be served with the correct CORs headers.
153+
availableSkins: [
154+
{ url: "./green.wsz", name: "Green Dimension V2" },
155+
{ url: "./osx.wsz", name: "Mac OSX v1.5 (Aqua)" },
156+
],
183157

184-
// Optional. Provide a way to extend the behavior of the button ADD URL.
185-
// **Since** 1.4.1
186-
handleAddUrlEvent: async () => {
187-
// Return an optional array of `Track` objects or null.
158+
// Optional. An object representing the initial layout of the windows.
159+
// Valid keys are `main`, `equalizer`, `playlist` and `milkdrop`. All windows
160+
// are optional.
161+
//
162+
// - Each provided window must specify a `position` object with `top` and
163+
// `left` which specify pixel offsets.
164+
// - Each provided window, except for
165+
// `milkdrop` may specify a `shadeMode` boolean.
166+
// - Each provided window may specify a `closed` boolean.
167+
// - The playlist and milkdrop windows may specify a `size` object with
168+
// `extraHeight` and `extraWidth`.
169+
//
170+
// **Note:** After windows are positioned, they are then centered _as a group_ within the
171+
// DOM element that Webamp is rendered into.
172+
windowLayout: {
173+
main: {
174+
position: { top: 0, left: 0 },
175+
shadeMode: true,
176+
closed: false,
177+
},
178+
equalizer: {
179+
position: { top: 0, left: 0 },
180+
shadeMode: true,
181+
closed: false,
182+
},
183+
playlist: {
184+
position: { top: 0, left: 0 },
185+
shadeMode: true,
186+
// Number of additional sprites by which to expand the window.
187+
size: { extraHeight: 1, extraHeight: 10 },
188+
closed: false,
188189
},
190+
},
191+
192+
// Optional. (Default: `false`) Should double size mode be enabled?
193+
// **Note:** In keeping with the original Winamp, double size mode
194+
// does not apply to resizable windows like the equalizer or Milkdrop.
195+
enableDoubleSizeMode: true,
196+
197+
// Optional. (Default: `false`) Should global hotkeys be enabled?
198+
enableHotkeys: true,
189199

190-
// Optional. Provide a way to extend the behavior of the playlist button LOAD LIST.
191-
// **Since** 1.4.1
192-
handleLoadListEvent: async () => {
193-
// Return an optional array of `Track` objects or null.
200+
// Optional. (Default: `0`) The zIndex that Webamp should use.
201+
zIndex: 99999,
202+
203+
// Optional. An array of additional file pickers.
204+
// These will appear in the "Options" menu under "Play".
205+
// In the demo site, This option is used to provide a "Dropbox" file
206+
// picker.
207+
filePickers: [
208+
{
209+
// The name that will appear in the context menu.
210+
contextMenuName: "My File Picker...",
211+
// A function which returns a Promise that resolves to
212+
// an array of `track`s (see above)
213+
filePicker: () =>
214+
Promise.resolve([
215+
{
216+
url: "./rick_roll.mp3",
217+
},
218+
]),
219+
// A boolean indicating if this options should be made
220+
// available when the user is offline.
221+
requiresNetwork: true,
194222
},
223+
],
224+
225+
// Optional. Provide a custom way to derive `Track` objects from a drop event.
226+
// Useful if your website has some DOM representation of a track that you can map to a URL/blob.
227+
handleTrackDropEvent: async (e) => {
228+
// Return an array of `Track` objects, see documentation below, or `null` to get the default drop behavior.
229+
// You may optionally wrap the return value in a promise.
230+
},
231+
232+
// Optional. Provide a way to extend the behavior of the button ADD URL.
233+
// **Since** 1.4.1
234+
handleAddUrlEvent: async () => {
235+
// Return an optional array of `Track` objects or null.
236+
},
237+
238+
// Optional. Provide a way to extend the behavior of the playlist button LOAD LIST.
239+
// **Since** 1.4.1
240+
handleLoadListEvent: async () => {
241+
// Return an optional array of `Track` objects or null.
242+
},
195243

196-
// Optional. Provide a way to extend the behavior of the playlist button SAVE LIST.
197-
// Where tracks: Track[]
198-
// **Since** 1.4.1
199-
handleSaveListEvent: (tracks) => {}
244+
// Optional. Provide a way to extend the behavior of the playlist button SAVE LIST.
245+
// Where tracks: Track[]
246+
// **Since** 1.4.1
247+
handleSaveListEvent: (tracks) => {},
200248
};
201249
const webamp = new Webamp(options);
202250
```

packages/webamp/js/reducers/windows.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ const defaultWindowsState: WindowsState = {
8080
hotkey: "Alt+E",
8181
position: { x: 0, y: 0 },
8282
},
83+
[WINDOWS.MILKDROP]: {
84+
title: "Milkdrop",
85+
size: [0, 0],
86+
open: false,
87+
shade: false,
88+
canResize: true,
89+
canShade: false,
90+
canDouble: false,
91+
position: { x: 0, y: 0 },
92+
},
8393
},
8494
browserWindowSize: { width: 0, height: 0 },
8595
windowOrder: [
@@ -101,14 +111,8 @@ const windows = (
101111
genWindows: {
102112
...state.genWindows,
103113
[WINDOWS.MILKDROP]: {
104-
title: "Milkdrop",
105-
size: [0, 0],
114+
...state.genWindows[WINDOWS.MILKDROP],
106115
open: action.open,
107-
shade: false,
108-
canResize: true,
109-
canShade: false,
110-
canDouble: false,
111-
position: { x: 0, y: 0 },
112116
},
113117
},
114118
};

0 commit comments

Comments
 (0)