buncha changes
This commit is contained in:
parent
119a15eb3d
commit
bf2edb3073
5 changed files with 114 additions and 20 deletions
|
@ -28,9 +28,6 @@ public class Wavelet.Application : Adw.Application {
|
||||||
flags: ApplicationFlags.DEFAULT_FLAGS
|
flags: ApplicationFlags.DEFAULT_FLAGS
|
||||||
);
|
);
|
||||||
|
|
||||||
playbin = Gst.ElementFactory.make ("playbin3", null);
|
|
||||||
assert (playbin != null);
|
|
||||||
|
|
||||||
var app_config_dir = Path.build_filename (Environment.get_user_config_dir (), "wavelet");
|
var app_config_dir = Path.build_filename (Environment.get_user_config_dir (), "wavelet");
|
||||||
try {
|
try {
|
||||||
File.new_build_filename (app_config_dir).make_directory_with_parents ();
|
File.new_build_filename (app_config_dir).make_directory_with_parents ();
|
||||||
|
@ -89,12 +86,66 @@ public class Wavelet.Application : Adw.Application {
|
||||||
});
|
});
|
||||||
|
|
||||||
win.play_queue.play_now.connect ((song) => {
|
win.play_queue.play_now.connect ((song) => {
|
||||||
|
win.play_position.sensitive = false;
|
||||||
|
|
||||||
playbin.set_state (Gst.State.READY);
|
playbin.set_state (Gst.State.READY);
|
||||||
playbin.set ("uri", api.stream_uri (song.id));
|
playbin.set ("uri", api.stream_uri (song.id));
|
||||||
playbin.set_state (Gst.State.PLAYING);
|
playbin.set_state (Gst.State.PLAYING);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
win.setup.load (config_db);
|
win.setup.load (config_db);
|
||||||
|
|
||||||
|
playbin = Gst.ElementFactory.make ("playbin3", null);
|
||||||
|
assert (playbin != null);
|
||||||
|
|
||||||
|
win.notify["volume"].connect ((s, p) => {
|
||||||
|
// gst docs: Volume sliders should usually use a cubic volume.
|
||||||
|
((Gst.Audio.StreamVolume) playbin).set_volume (Gst.Audio.StreamVolumeFormat.CUBIC, win.volume);
|
||||||
|
});
|
||||||
|
|
||||||
|
win.mute.clicked.connect (() => {
|
||||||
|
var vol = (Gst.Audio.StreamVolume) playbin;
|
||||||
|
if (vol.get_mute ()) {
|
||||||
|
win.show_unmute ();
|
||||||
|
vol.set_mute (false);
|
||||||
|
} else {
|
||||||
|
win.show_mute ();
|
||||||
|
vol.set_mute (true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Timeout.add (100, () => {
|
||||||
|
int64 position_ns;
|
||||||
|
if (playbin.query_position (Gst.Format.TIME, out position_ns)) {
|
||||||
|
win.play_position_ms = position_ns / 1000000;
|
||||||
|
}
|
||||||
|
return Source.CONTINUE;
|
||||||
|
});
|
||||||
|
|
||||||
|
playbin.get_bus ().add_watch (Priority.DEFAULT, (bus, message) => {
|
||||||
|
switch (message.type) {
|
||||||
|
case Gst.MessageType.ASYNC_DONE:
|
||||||
|
win.play_position.sensitive = true;
|
||||||
|
|
||||||
|
int64 duration_ns;
|
||||||
|
assert(playbin.query_duration (Gst.Format.TIME, out duration_ns));
|
||||||
|
print("%lld\n", duration_ns);
|
||||||
|
|
||||||
|
win.play_position_ms = 0;
|
||||||
|
win.play_duration_ms = duration_ns / 1000000;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
print ("%s\n", message.type.to_string ());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
Signal.connect (playbin, "about-to-finish", () => {
|
||||||
|
print("about to finish\n");
|
||||||
|
}, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void on_about_action () {
|
private void on_about_action () {
|
||||||
|
|
|
@ -12,6 +12,7 @@ wavelet_sources = [
|
||||||
wavelet_deps = [
|
wavelet_deps = [
|
||||||
config_dep,
|
config_dep,
|
||||||
dependency('gstreamer-1.0'),
|
dependency('gstreamer-1.0'),
|
||||||
|
dependency('gstreamer-audio-1.0'),
|
||||||
dependency('gtk4'),
|
dependency('gtk4'),
|
||||||
dependency('json-glib-1.0'),
|
dependency('json-glib-1.0'),
|
||||||
dependency('libadwaita-1', version: '>= 1.4'),
|
dependency('libadwaita-1', version: '>= 1.4'),
|
||||||
|
|
|
@ -29,10 +29,12 @@ public class Wavelet.PlayQueue : Adw.NavigationPage {
|
||||||
|
|
||||||
construct {
|
construct {
|
||||||
this.songs = new ListStore (typeof (Song));
|
this.songs = new ListStore (typeof (Song));
|
||||||
this.list_view.model = new Gtk.NoSelection (this.songs);
|
this.current = 0;
|
||||||
|
|
||||||
|
this.list_view.model = new Gtk.NoSelection (this.songs);
|
||||||
this.list_view.activate.connect ((position) => {
|
this.list_view.activate.connect ((position) => {
|
||||||
Song song = (Song) this.songs.get_item(position);
|
this.current = position;
|
||||||
|
Song song = (Song) this.songs.get_item (position);
|
||||||
this.play_now (song);
|
this.play_now (song);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -45,4 +47,13 @@ public class Wavelet.PlayQueue : Adw.NavigationPage {
|
||||||
public void queue (Song song) {
|
public void queue (Song song) {
|
||||||
this.songs.append (song);
|
this.songs.append (song);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Song? next () {
|
||||||
|
if (this.current >= this.songs.get_n_items ()) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
this.current += 1;
|
||||||
|
return (Song) this.songs.get_item (this.current);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,23 +126,32 @@ template $WaveletWindow: Adw.ApplicationWindow {
|
||||||
halign: start;
|
halign: start;
|
||||||
orientation: horizontal;
|
orientation: horizontal;
|
||||||
|
|
||||||
Label {
|
Label play_position_label {
|
||||||
|
styles [
|
||||||
|
"numeric",
|
||||||
|
]
|
||||||
|
|
||||||
label: "00:00";
|
label: "00:00";
|
||||||
}
|
}
|
||||||
|
|
||||||
Scale {
|
Scale play_position {
|
||||||
orientation: horizontal;
|
orientation: horizontal;
|
||||||
width-request: 200;
|
width-request: 200;
|
||||||
|
sensitive: false;
|
||||||
|
|
||||||
adjustment: Adjustment {
|
adjustment: Adjustment {
|
||||||
lower: 0;
|
lower: 0;
|
||||||
upper: 100;
|
value: bind template.play_position_ms bidirectional;
|
||||||
value: 0;
|
upper: bind template.play_duration_ms;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Label {
|
Label play_duration {
|
||||||
label: "99:99";
|
styles [
|
||||||
|
"numeric",
|
||||||
|
]
|
||||||
|
|
||||||
|
label: "00:00";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -175,7 +184,7 @@ template $WaveletWindow: Adw.ApplicationWindow {
|
||||||
valign: center;
|
valign: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
Button {
|
Button mute {
|
||||||
icon-name: "audio-volume-high";
|
icon-name: "audio-volume-high";
|
||||||
valign: center;
|
valign: center;
|
||||||
}
|
}
|
||||||
|
@ -185,16 +194,11 @@ template $WaveletWindow: Adw.ApplicationWindow {
|
||||||
width-request: 130;
|
width-request: 130;
|
||||||
|
|
||||||
adjustment: Adjustment {
|
adjustment: Adjustment {
|
||||||
lower: 0;
|
lower: 0.0;
|
||||||
upper: 100;
|
value: bind template.volume bidirectional;
|
||||||
value: 100;
|
upper: 1.0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Button {
|
|
||||||
icon-name: "media-playlist-consecutive";
|
|
||||||
valign: center;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,11 +31,30 @@ public class Wavelet.Window : Adw.ApplicationWindow {
|
||||||
[GtkChild] public unowned Wavelet.PlayQueue play_queue;
|
[GtkChild] public unowned Wavelet.PlayQueue play_queue;
|
||||||
[GtkChild] public unowned Adw.ButtonRow shuffle_all_tracks;
|
[GtkChild] public unowned Adw.ButtonRow shuffle_all_tracks;
|
||||||
|
|
||||||
|
[GtkChild] public unowned Gtk.Button mute;
|
||||||
|
[GtkChild] private unowned Gtk.Label play_position_label;
|
||||||
|
[GtkChild] public unowned Gtk.Scale play_position;
|
||||||
|
[GtkChild] private unowned Gtk.Label play_duration;
|
||||||
|
|
||||||
|
public int64 play_position_ms { get; set; default = 0; }
|
||||||
|
public int64 play_duration_ms { get; set; default = 1; }
|
||||||
|
|
||||||
|
public double volume { get; set; default = 1.0; }
|
||||||
|
|
||||||
public Window (Gtk.Application app) {
|
public Window (Gtk.Application app) {
|
||||||
Object (application: app);
|
Object (application: app);
|
||||||
}
|
}
|
||||||
|
|
||||||
construct {
|
construct {
|
||||||
|
this.notify["play-position-ms"].connect ((s, p) => {
|
||||||
|
int seconds = (int)(this.play_position_ms/1000);
|
||||||
|
this.play_position_label.label = "%02d:%02d".printf(seconds/60, seconds%60);
|
||||||
|
});
|
||||||
|
this.notify["play-duration-ms"].connect ((s, p) => {
|
||||||
|
int seconds = (int)(this.play_duration_ms/1000);
|
||||||
|
this.play_duration.label = "%02d:%02d".printf(seconds/60, seconds%60);
|
||||||
|
});
|
||||||
|
|
||||||
this.sidebar.row_activated.connect ((row) => {
|
this.sidebar.row_activated.connect ((row) => {
|
||||||
if (row == this.sidebar_setup) {
|
if (row == this.sidebar_setup) {
|
||||||
this.stack.set_visible_child_name("setup");
|
this.stack.set_visible_child_name("setup");
|
||||||
|
@ -46,4 +65,12 @@ public class Wavelet.Window : Adw.ApplicationWindow {
|
||||||
|
|
||||||
this.sidebar.select_row (this.sidebar.get_row_at_index (0));
|
this.sidebar.select_row (this.sidebar.get_row_at_index (0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void show_mute () {
|
||||||
|
this.mute.icon_name = "audio-volume-muted";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void show_unmute () {
|
||||||
|
this.mute.icon_name = "audio-volume-high";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue