buncha changes

This commit is contained in:
Erica Z 2024-10-11 06:57:01 +00:00
parent 119a15eb3d
commit bf2edb3073
5 changed files with 114 additions and 20 deletions

View file

@ -28,9 +28,6 @@ public class Wavelet.Application : Adw.Application {
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");
try {
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_position.sensitive = false;
playbin.set_state (Gst.State.READY);
playbin.set ("uri", api.stream_uri (song.id));
playbin.set_state (Gst.State.PLAYING);
});
});
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 () {

View file

@ -12,6 +12,7 @@ wavelet_sources = [
wavelet_deps = [
config_dep,
dependency('gstreamer-1.0'),
dependency('gstreamer-audio-1.0'),
dependency('gtk4'),
dependency('json-glib-1.0'),
dependency('libadwaita-1', version: '>= 1.4'),

View file

@ -29,9 +29,11 @@ public class Wavelet.PlayQueue : Adw.NavigationPage {
construct {
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.current = position;
Song song = (Song) this.songs.get_item (position);
this.play_now (song);
});
@ -45,4 +47,13 @@ public class Wavelet.PlayQueue : Adw.NavigationPage {
public void queue (Song 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);
}
}
}

View file

@ -126,23 +126,32 @@ template $WaveletWindow: Adw.ApplicationWindow {
halign: start;
orientation: horizontal;
Label {
Label play_position_label {
styles [
"numeric",
]
label: "00:00";
}
Scale {
Scale play_position {
orientation: horizontal;
width-request: 200;
sensitive: false;
adjustment: Adjustment {
lower: 0;
upper: 100;
value: 0;
value: bind template.play_position_ms bidirectional;
upper: bind template.play_duration_ms;
};
}
Label {
label: "99:99";
Label play_duration {
styles [
"numeric",
]
label: "00:00";
}
}
}
@ -175,7 +184,7 @@ template $WaveletWindow: Adw.ApplicationWindow {
valign: center;
}
Button {
Button mute {
icon-name: "audio-volume-high";
valign: center;
}
@ -185,16 +194,11 @@ template $WaveletWindow: Adw.ApplicationWindow {
width-request: 130;
adjustment: Adjustment {
lower: 0;
upper: 100;
value: 100;
lower: 0.0;
value: bind template.volume bidirectional;
upper: 1.0;
};
}
Button {
icon-name: "media-playlist-consecutive";
valign: center;
}
}
};
}

View file

@ -31,11 +31,30 @@ public class Wavelet.Window : Adw.ApplicationWindow {
[GtkChild] public unowned Wavelet.PlayQueue play_queue;
[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) {
Object (application: app);
}
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) => {
if (row == this.sidebar_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));
}
public void show_mute () {
this.mute.icon_name = "audio-volume-muted";
}
public void show_unmute () {
this.mute.icon_name = "audio-volume-high";
}
}