Skip to content

Commit 4dc0295

Browse files
Add soundscape selection from miniplayer, 2 new soundscapes
1 parent 2d09b5d commit 4dc0295

8 files changed

+129
-27
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ Additionally, the plugin makes a call to this github repository occasionally to
6565
- [Sky: Children of the Light soundtrack](https://www.youtube.com/watch?v=87etrUp83Yc)
6666
- [Vampire: The Masquerade – Bloodlines Ambient Playlist](https://www.youtube.com/watch?v=pCZxb43L_Ag)
6767
- [ChillSynth FM - lofi synthwave radio for retro dreaming](https://www.youtube.com/watch?v=UedTcufyrHc)
68+
- [peaceful piano radio 🎹 - music to focus/study to](https://www.youtube.com/watch?v=vMxYL4Cj85Y)
69+
- [synthwave radio 🌌 - beats to chill/game to](https://www.youtube.com/watch?v=4xDzrJKXOOY)
6870

6971
## Reporting Issues
7072

main.ts

+89
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export default class SoundscapesPlugin extends Plugin {
4444
pauseButton: HTMLButtonElement;
4545
nextButton: HTMLButtonElement;
4646
previousButton: HTMLButtonElement;
47+
changeSoundscapeSelect: HTMLSelectElement;
4748
nowPlayingRoot: HTMLDivElement;
4849
nowPlaying: HTMLDivElement;
4950
volumeMutedIcon: HTMLDivElement;
@@ -341,26 +342,47 @@ export default class SoundscapesPlugin extends Plugin {
341342
* Create all the UI elements
342343
*/
343344
createControls() {
345+
// Previous Button
344346
this.previousButton = this.statusBarItem.createEl("button", {
345347
cls: "soundscapesroot-previousbutton",
346348
});
347349
setIcon(this.previousButton, "skip-back");
348350
this.previousButton.onclick = () => this.previous();
349351

352+
// Play Button
350353
this.playButton = this.statusBarItem.createEl("button", {});
351354
setIcon(this.playButton, "play");
352355
this.playButton.onclick = () => this.play();
353356

357+
// Pause Button
354358
this.pauseButton = this.statusBarItem.createEl("button", {});
355359
setIcon(this.pauseButton, "pause");
356360
this.pauseButton.onclick = () => this.pause();
357361

362+
// Next Button
358363
this.nextButton = this.statusBarItem.createEl("button", {
359364
cls: "soundscapesroot-nextbutton",
360365
});
361366
setIcon(this.nextButton, "skip-forward");
362367
this.nextButton.onclick = () => this.next();
363368

369+
// Change Soundscape Button
370+
const changeSoundscapeButton = this.statusBarItem.createEl("button", {
371+
cls: "soundscapesroot-changesoundscapebutton",
372+
});
373+
setIcon(changeSoundscapeButton, "list-music");
374+
this.changeSoundscapeSelect = changeSoundscapeButton.createEl(
375+
"select",
376+
{
377+
cls: "soundscapesroot-changesoundscapeselect",
378+
attr: {
379+
id: "soundscapesroot-changesoundscapeselect",
380+
},
381+
}
382+
);
383+
this.populateChangeSoundscapeButton();
384+
385+
// Now Playing
364386
this.nowPlayingRoot = this.statusBarItem.createEl("div", {
365387
cls: "soundscapesroot-nowplaying",
366388
});
@@ -369,6 +391,7 @@ export default class SoundscapesPlugin extends Plugin {
369391
});
370392
this.toggleNowPlayingScroll();
371393

394+
// Volume control
372395
const volumeIcons = this.statusBarItem.createEl("div", {
373396
cls: "soundscapesroot-volumeIcons",
374397
});
@@ -405,6 +428,45 @@ export default class SoundscapesPlugin extends Plugin {
405428
);
406429
}
407430

431+
/**
432+
* Populates the dropdown on the miniplayer with all available soundscapes
433+
*/
434+
populateChangeSoundscapeButton() {
435+
this.changeSoundscapeSelect.replaceChildren();
436+
437+
Object.values(SOUNDSCAPES).forEach((soundscape) => {
438+
this.changeSoundscapeSelect.createEl("option", {
439+
text: soundscape.name,
440+
value: soundscape.id,
441+
});
442+
});
443+
444+
this.settings.customSoundscapes.forEach((customSoundscape) => {
445+
if (customSoundscape.tracks.length > 0) {
446+
this.changeSoundscapeSelect.createEl("option", {
447+
text: customSoundscape.name,
448+
value: `${SOUNDSCAPE_TYPE.CUSTOM}_${customSoundscape.id}`,
449+
});
450+
}
451+
});
452+
453+
this.changeSoundscapeSelect.createEl("option", {
454+
text: "My Music",
455+
value: SOUNDSCAPE_TYPE.MY_MUSIC,
456+
});
457+
458+
this.changeSoundscapeSelect.value = this.settings.soundscape;
459+
460+
this.changeSoundscapeSelect.addEventListener(
461+
"change",
462+
(event: Event) => {
463+
this.changeSoundscape(
464+
(event?.target as HTMLSelectElement).value
465+
);
466+
}
467+
);
468+
}
469+
408470
/******************************************************************************************************************/
409471
//#endregion Create UI Elements
410472
/******************************************************************************************************************/
@@ -593,6 +655,30 @@ export default class SoundscapesPlugin extends Plugin {
593655
}
594656
}
595657

658+
/**
659+
* Changes the currently playing soundscape and triggers other downstream side effects
660+
* @param soundscape
661+
*/
662+
changeSoundscape(soundscape: string) {
663+
this.settings.soundscape = soundscape;
664+
665+
if (this.settings.soundscape.startsWith(`${SOUNDSCAPE_TYPE.CUSTOM}_`)) {
666+
this.currentTrackIndex = 0;
667+
}
668+
669+
// When we select MY_MUSIC, force a re-index
670+
// Also show the ribbon button!
671+
if (this.settings.soundscape === SOUNDSCAPE_TYPE.MY_MUSIC) {
672+
this.indexMusicLibrary();
673+
this.ribbonButton.show();
674+
} else {
675+
this.ribbonButton.hide();
676+
}
677+
678+
this.onSoundscapeChange();
679+
this.saveSettings();
680+
}
681+
596682
/******************************************************************************************************************/
597683
//#endregion Control Player
598684
/******************************************************************************************************************/
@@ -769,6 +855,9 @@ export default class SoundscapesPlugin extends Plugin {
769855
this.localPlayer.pause(); // Edge Case: When switching from MyMusic to Youtube, the youtube video keeps playing
770856
}
771857

858+
// Keep miniplayer's soundscape selection button up to date
859+
this.changeSoundscapeSelect.value = this.settings.soundscape;
860+
772861
this.saveSettings();
773862
}
774863

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "soundscapes",
33
"name": "Soundscapes",
4-
"version": "1.3.0",
4+
"version": "1.4.0",
55
"minAppVersion": "0.15.0",
66
"description": "Adds a music/ambiance (E.g. lofi, white noise) player to the status bar to help with concentration. Also allows you to play your own local music files.",
77
"author": "Andrew McGivery",

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obsidian-soundscapes",
3-
"version": "1.3.0",
3+
"version": "1.4.0",
44
"description": "A plugin for Obsidian.MD that adds a music/ambiance player to the status bar.",
55
"main": "dist/main.js",
66
"scripts": {

src/Settings/Settings.ts

+4-24
Original file line numberDiff line numberDiff line change
@@ -71,30 +71,7 @@ export class SoundscapesSettingsTab extends PluginSettingTab {
7171
component.setValue(this.plugin.settings.soundscape);
7272

7373
component.onChange((value: string) => {
74-
this.plugin.settings.soundscape = value;
75-
76-
if (
77-
this.plugin.settings.soundscape.startsWith(
78-
`${SOUNDSCAPE_TYPE.CUSTOM}_`
79-
)
80-
) {
81-
this.plugin.currentTrackIndex = 0;
82-
}
83-
84-
// When we select MY_MUSIC, force a re-index
85-
// Also show the ribbon button!
86-
if (
87-
this.plugin.settings.soundscape ===
88-
SOUNDSCAPE_TYPE.MY_MUSIC
89-
) {
90-
this.plugin.indexMusicLibrary();
91-
this.plugin.ribbonButton.show();
92-
} else {
93-
this.plugin.ribbonButton.hide();
94-
}
95-
96-
this.plugin.onSoundscapeChange();
97-
this.plugin.saveSettings();
74+
this.plugin.changeSoundscape(value);
9875
this.display();
9976
});
10077
});
@@ -148,6 +125,7 @@ export class SoundscapesSettingsTab extends PluginSettingTab {
148125
] = modifiedCustomSoundscape;
149126
this.plugin.saveSettings();
150127
this.display();
128+
this.plugin.populateChangeSoundscapeButton();
151129
}
152130
).open();
153131
});
@@ -176,6 +154,7 @@ export class SoundscapesSettingsTab extends PluginSettingTab {
176154

177155
this.plugin.saveSettings();
178156
this.display();
157+
this.plugin.populateChangeSoundscapeButton();
179158
},
180159
"Remove custom soundscape",
181160
`This will remove your custom soundscape "${customSoundscape.name}". Are you sure?`,
@@ -200,6 +179,7 @@ export class SoundscapesSettingsTab extends PluginSettingTab {
200179
);
201180
this.plugin.saveSettings();
202181
this.display();
182+
this.plugin.populateChangeSoundscapeButton();
203183
}
204184
).open();
205185
});

src/Soundscapes.ts

+16
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,22 @@ const SOUNDSCAPES: Record<string, Soundscape> = {
122122
youtubeId: "UedTcufyrHc",
123123
type: SOUNDSCAPE_TYPE.STANDARD,
124124
},
125+
peacefulpiano: {
126+
id: "peacefulpiano",
127+
name: "Peaceful piano radio",
128+
nowPlayingText: "Peaceful piano radio",
129+
isLiveVideo: true,
130+
youtubeId: "vMxYL4Cj85Y",
131+
type: SOUNDSCAPE_TYPE.STANDARD,
132+
},
133+
synthwave: {
134+
id: "synthwave",
135+
name: "Synthwave radio",
136+
nowPlayingText: "Synthwave radio",
137+
isLiveVideo: true,
138+
youtubeId: "4xDzrJKXOOY",
139+
type: SOUNDSCAPE_TYPE.STANDARD,
140+
},
125141
};
126142

127143
export default SOUNDSCAPES;

styles.scss

+14
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@
4747
margin-left: 4px;
4848
}
4949

50+
.soundscapesroot-changesoundscapebutton {
51+
margin-left: 4px;
52+
position: relative;
53+
}
54+
55+
.soundscapesroot-changesoundscapeselect {
56+
opacity: 0;
57+
position: absolute;
58+
top: 0;
59+
left: 0;
60+
bottom: 0;
61+
right: 0;
62+
}
63+
5064
.soundscapesroot-nowplaying {
5165
margin: 0 12px;
5266
width: 150px;

versions.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"1.2.0-beta.3": "0.15.0",
88
"1.2.0-beta.4": "0.15.0",
99
"1.2.0": "0.15.0",
10-
"1.3.0": "0.15.0"
10+
"1.3.0": "0.15.0",
11+
"1.4.0": "0.15.0"
1112
}

0 commit comments

Comments
 (0)