diff --git a/src/Core/Lyric.vala b/src/Core/Lyric.vala index b8b2b90..d4dea70 100644 --- a/src/Core/Lyric.vala +++ b/src/Core/Lyric.vala @@ -85,6 +85,8 @@ public class Lyrics.Lyric : Object { iterator.next (); } + if (iterator.has_previous ()) iterator.previous (); + return iterator; } diff --git a/src/Core/LyricsService.vala b/src/Core/LyricsService.vala index ad4df3d..c170308 100644 --- a/src/Core/LyricsService.vala +++ b/src/Core/LyricsService.vala @@ -2,6 +2,7 @@ public class Lyrics.LyricsService : Object { public State state { get; set; } IRepository lyric_repository; public Lyric? lyric { get; set; } + GLib.MainLoop request_event_loop; public LyricsService (IRepository repository) { lyric_repository = repository; @@ -9,7 +10,11 @@ public class Lyrics.LyricsService : Object { } public void set_player (Player player) { - GLib.MainLoop loop = new GLib.MainLoop (); + if (request_event_loop != null) { + request_event_loop.quit (); + } + + request_event_loop = new GLib.MainLoop (); if (player.current_song == null) { state = State.UNKNOWN; @@ -17,9 +22,10 @@ public class Lyrics.LyricsService : Object { } request_lyric.begin (player.current_song, () => { - loop.quit (); + request_event_loop.quit (); }); - loop.run (); + + request_event_loop.run (); } public signal void set_lyric (Lyric lyric) { diff --git a/src/Core/Players.vala b/src/Core/Players.vala index f7d6eea..10b8db6 100644 --- a/src/Core/Players.vala +++ b/src/Core/Players.vala @@ -43,8 +43,6 @@ public class Lyrics.Players : Object { scanner.setup_dbus (); notify["active-player"].connect (() => on_active_player_changed (active_player)); - notify["active-player"].connect (() => on_active_player_changed (active_player)); - } public bool add (Player player) { diff --git a/src/View/SettingsPopover.vala b/src/View/Settings/SettingsPopover.vala similarity index 86% rename from src/View/SettingsPopover.vala rename to src/View/Settings/SettingsPopover.vala index 13d56d4..9190b8f 100644 --- a/src/View/SettingsPopover.vala +++ b/src/View/Settings/SettingsPopover.vala @@ -25,14 +25,19 @@ public class Lyrics.SettingsPopover : Gtk.Popover { combobox = create_combobox (); var reset_default_button = create_reset_button (); + var offset_label = new Gtk.Label (_("Offset:")); + var offset_input = new Gtk.SpinButton.with_range (-100, 100, 1); + grid.attach (font_selection_label, 0, 0); grid.attach (font_selection_btn, 1, 0); grid.attach (lyrics_folder_label, 0, 1); grid.attach (folder_chooser_button, 1, 1); grid.attach (window_behavior_label, 0, 2); grid.attach (combobox, 1, 2); - grid.attach (create_translucid_switch (), 0, 3, 2); - grid.attach (reset_default_button, 0, 4, 2); + grid.attach (offset_label, 0, 3); + grid.attach (offset_input, 1, 3); + grid.attach (create_translucid_switch (), 0, 4, 2); + grid.attach (reset_default_button, 0, 5, 2); grid.show_all (); add (grid); @@ -41,6 +46,7 @@ public class Lyrics.SettingsPopover : Gtk.Popover { Application.settings.bind ("window-keep-above", combobox, "active-id", GLib.SettingsBindFlags.DEFAULT); Application.settings.bind ("window-out-of-focus-translucid", opacity_switch, "active", GLib.SettingsBindFlags.DEFAULT); Application.settings.bind ("font", font_selection_btn, "font", GLib.SettingsBindFlags.DEFAULT); + Application.settings.bind ("offset", offset_input, "value", GLib.SettingsBindFlags.DEFAULT); } Gtk.ComboBox create_combobox () { @@ -70,6 +76,7 @@ public class Lyrics.SettingsPopover : Gtk.Popover { Application.settings.reset ("window-keep-above"); Application.settings.reset ("window-out-of-focus-translucid"); Application.settings.reset ("font"); + Application.settings.reset ("offset"); }); return btn; diff --git a/tests/unit/Parser/LrcParserTest.vala b/tests/unit/Parser/LrcParserTest.vala index 63bf19b..3a98841 100644 --- a/tests/unit/Parser/LrcParserTest.vala +++ b/tests/unit/Parser/LrcParserTest.vala @@ -108,13 +108,13 @@ public class Unit.Parser.LrcParserTest : Unit.TestCase { assert_cmpstr ( lrc.get_current_line (one_minute_in_us), GLib.CompareOperator.EQ, - "Chorus" + "But silence is all I hear" ); assert_cmpstr ( lrc.get_current_line (2 * one_minute_in_us), GLib.CompareOperator.EQ, - "Verse 2" + "Hoping for a glimpse of your light" ); } @@ -150,13 +150,13 @@ public class Unit.Parser.LrcParserTest : Unit.TestCase { assert_cmpstr ( lrc.get_current_line (one_minute_in_us), GLib.CompareOperator.EQ, - "Chorus" + "But silence is all I hear" ); assert_cmpstr ( lrc.get_current_line (2 * one_minute_in_us), GLib.CompareOperator.EQ, - "Verse 2" + "Hoping for a glimpse of your light" ); } }