From 70245c50d2585b45d027064a72bb5c0fd50bcea5 Mon Sep 17 00:00:00 2001 From: ItsMicin Date: Sun, 21 Nov 2021 07:19:45 +0700 Subject: [PATCH] new --- src/AudioMix.vala | 1 - src/CameraFlash.vala | 39 ----------------- src/Player.vala | 95 ++++++++++++++++++++++++++++++++++++++++- src/PreviewPopover.vala | 9 ++-- src/TextMix.vala | 18 +++----- src/VideoGrid.vala | 8 ++-- src/VideoMix.vala | 64 +++++++++++---------------- 7 files changed, 136 insertions(+), 98 deletions(-) diff --git a/src/AudioMix.vala b/src/AudioMix.vala index 29090bb..48b7e77 100755 --- a/src/AudioMix.vala +++ b/src/AudioMix.vala @@ -52,7 +52,6 @@ namespace Niki { audioamplify = Gst.ElementFactory.make ("audioamplify", "audioamplify"); audioamplify["amplification"] = 1.16; spectrum = Gst.ElementFactory.make ("spectrum", "spectrum"); - spectrum["interval"] = (uint64)120000000; spectrum["bands"] = 10; audiosink = Gst.ElementFactory.make (AUDIORENDER [NikiApp.settings.get_int ("audiorender-options")], AUDIORENDER [NikiApp.settings.get_int ("audiorender-options")]); add_many (audioqueue, audiotee, capsfilter, equalizer, spectrum, audioamplify, scaletempo, audiosink); diff --git a/src/CameraFlash.vala b/src/CameraFlash.vala index 66b172d..8768ed3 100755 --- a/src/CameraFlash.vala +++ b/src/CameraFlash.vala @@ -19,17 +19,11 @@ * Authored by: torikulhabib */ -[DBus (name = "org.gnome.SettingsDaemon.Power.Screen")] -private interface BrightnessSettings : GLib.Object { - public abstract int brightness {owned get; set; } -} namespace Niki { public class CameraFlash : Gtk.Window { private uint fade_timeout = 0; private uint flash_timeout = 0; - private int start_brighnest; public signal bool capture_now (); - private BrightnessSettings? brightness_settings; construct { var headerbar = new Gtk.HeaderBar (); @@ -39,12 +33,6 @@ namespace Niki { headerbar.get_style_context ().add_class ("default-decoration"); set_titlebar (headerbar); headerbar.hide (); - try { - brightness_settings = Bus.get_proxy_sync (BusType.SESSION, "org.gnome.SettingsDaemon.Power", - "/org/gnome/SettingsDaemon/Power", DBusProxyFlags.GET_INVALIDATED_PROPERTIES); - } catch (IOError e) { - warning (e.message); - } } private bool flash_opacity_fade () { @@ -52,9 +40,6 @@ namespace Niki { if (opacity <= 0.1) { set_keep_above (false); destroy (); - if (lid_detect ()) { - brightness_settings.brightness = start_brighnest; - } Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = NikiApp.settings.get_boolean ("dark-style"); fade_timeout = 0; return Source.REMOVE; @@ -97,31 +82,7 @@ namespace Niki { get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT); Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = false; show_all (); - if (lid_detect ()) { - start_brighnest = brightness_settings.brightness; - } - Idle.add (bright_now); flash_timeout = Timeout.add (400, flash_start_fade); } - private static bool lid_detect () { - var interface_path = File.new_for_path ("/proc/acpi/button/lid/"); - try { - var enumerator = interface_path.enumerate_children ( GLib.FileAttribute.STANDARD_NAME, FileQueryInfoFlags.NONE); - FileInfo lid; - if ((lid = enumerator.next_file ()) != null) { - return true; - } - enumerator.close (); - } catch (GLib.Error err) { - critical ("%s", err.message); - } - return false; - } - private bool bright_now () { - if (lid_detect ()) { - brightness_settings.brightness = 80; - } - return Source.REMOVE; - } } } diff --git a/src/Player.vala b/src/Player.vala index 5b7cfc6..2f3109f 100644 --- a/src/Player.vala +++ b/src/Player.vala @@ -99,7 +99,7 @@ namespace Niki { } set { _seeked = value; - pipeline.seek_simple (Gst.Format.TIME, Gst.SeekFlags.FLUSH, (int64) ((seeked * duration) * 1000000000)); + pipeline.seek_simple (Gst.Format.TIME, Gst.SeekFlags.FLUSH | Gst.SeekFlags.SKIP | Gst.SeekFlags.ACCURATE, (int64) ((seeked * duration) * 1000000000)); } } @@ -205,13 +205,70 @@ namespace Niki { } } + private int _gamma; + public int gamma { + get { + return _gamma; + } + set { + _gamma = value; + } + } + + private int _saturation; + public int saturation { + get { + return _saturation; + } + set { + _saturation = value; + color_balance (); + } + } + + private int _brightness; + public int brightness { + get { + return _brightness; + } + set { + _brightness = value; + color_balance (); + } + } + + private int _contrast; + public int contrast { + get { + return _contrast; + } + set { + _contrast = value; + color_balance (); + } + } + + private int _hue; + public int hue { + get { + return _hue; + } + set { + _hue = value; + color_balance (); + } + } + construct { pipeline = Gst.ElementFactory.make ("playbin", "playbin"); videomix = new VideoMix (); audiomix = new AudioMix (); textmix = new TextMix (); + bind_property ("gamma", videomix, "gamma", BindingFlags.BIDIRECTIONAL); + bind_property ("saturation", videomix, "saturation", BindingFlags.BIDIRECTIONAL); videomix.videosink.pipeline_ready.connect (()=> { ready (); + color_balance (); unowned ClutterGst.Frame frame = videomix.videosink.get_frame (); size_change (frame.resolution.width, frame.resolution.height); if (subtitle_active != NikiApp.settings.get_boolean ("activate-subtitle")) { @@ -250,6 +307,40 @@ namespace Niki { registry.add_feature ((Gst.PluginFeature) factory); } + public void setvalue (int index, int valuescale) { + switch (index) { + case 0 : + gamma = valuescale * 10; + break; + case 1 : + brightness = valuescale * 10; + break; + case 2 : + contrast = valuescale * 10; + break; + case 3 : + saturation = valuescale * 10; + break; + case 4 : + hue = valuescale * 10; + break; + } + } + + private void color_balance () { + ((Gst.Video.ColorBalance) pipeline).list_channels ().foreach ((channel)=> { + if (channel.label == "SATURATION") { + ((Gst.Video.ColorBalance) pipeline).set_value (channel, saturation); + } else if (channel.label == "BRIGHTNESS") { + ((Gst.Video.ColorBalance) pipeline).set_value (channel, brightness); + } else if (channel.label == "CONTRAST") { + ((Gst.Video.ColorBalance) pipeline).set_value (channel, contrast); + } else if (channel.label == "HUE") { + ((Gst.Video.ColorBalance) pipeline).set_value (channel, hue); + } + }); + } + public void set_subtittle (string subtitle) { insert_last_video (uri, seconds_to_time ((int) (progress * duration)), progress); pipeline.set_state (Gst.State.NULL); @@ -385,7 +476,7 @@ namespace Niki { return; } double length = Math.sin (period); - period += Math.PI / 20; + period += Math.PI / 250; length += 1.1; length *= 100 * Gst.MSECOND; diff --git a/src/PreviewPopover.vala b/src/PreviewPopover.vala index 3d5a3ac..519f093 100755 --- a/src/PreviewPopover.vala +++ b/src/PreviewPopover.vala @@ -38,6 +38,7 @@ namespace Niki { playback.size_change.connect ((width, height) => { clutter_height = height; clutter_width = width; + clutter_resize (); }); clutter = new GtkClutter.Embed () { margin = 1 @@ -75,6 +76,8 @@ namespace Niki { hide.connect (()=> { playback.stop (); }); + var clear_content = new Clutter.Canvas (); + } private void load_label () { @@ -109,7 +112,7 @@ namespace Niki { if (NikiApp.settings.get_boolean ("audio-video")) { return; } - this.req_progress = p_progress; + this.req_progress = p_progress - 0.001; req_loop = loop; if (!visible || idle_id > 0) { return; @@ -155,11 +158,11 @@ namespace Niki { return; } cancel_timer (ref hide_timer_id); - clutter_resize (); show_timer_id = Timeout.add (350, () => { show_all (); if (req_progress >= 0) { set_preview_progress (req_progress, req_loop); + clutter_resize (); } show_timer_id = 0; return false; @@ -174,9 +177,9 @@ namespace Niki { return; } cancel_timer (ref show_timer_id); - clutter_resize (); hide_timer_id = Timeout.add (350, () => { hide (); + clutter_resize (); hide_timer_id = 0; return false; }); diff --git a/src/TextMix.vala b/src/TextMix.vala index 423ef00..ed36132 100755 --- a/src/TextMix.vala +++ b/src/TextMix.vala @@ -24,32 +24,28 @@ namespace Niki { private dynamic Gst.Element textqueue; private dynamic Gst.Element texttee; private dynamic Gst.Element textoverlay; - private dynamic Gst.Element subparse; private dynamic Gst.Element testsink; public TextMix () { texttee = Gst.ElementFactory.make ("tee", "tee"); textqueue = Gst.ElementFactory.make ("queue", "queue"); textoverlay = Gst.ElementFactory.make ("textoverlay", "textoverlay"); - subparse = Gst.ElementFactory.make ("subparse", "subparse"); - testsink = Gst.ElementFactory.make ("textsink", "autotextsink"); - add_many (textqueue, texttee, subparse, textoverlay, testsink); + testsink = Gst.ElementFactory.make ("textsink", "textsink"); + add_many (textqueue, texttee, textoverlay, testsink); add_pad (new Gst.GhostPad ("sink", texttee.get_static_pad ("sink"))); - textqueue.link_many (subparse, textoverlay, testsink); + textqueue.link_many (textoverlay, testsink); Gst.Pad sinkpad = textqueue.get_static_pad ("sink"); Gst.Pad pad = texttee.get_request_pad ("src_%u"); pad.link (sinkpad); - texttee["alloc-pad"] = pad; Gst.ControlSource cs_a = new Gst.Controller.LFOControlSource (); - cs_a.set ("frequency", (double) 0.5, "amplitude", (double) 0.5, "offset", (double) 0.5); + cs_a.set ("frequency", (double) 1.0); Gst.ControlSource cs_r = new Gst.Controller.LFOControlSource (); - cs_r.set ("frequency", (double) 0.19, "amplitude", (double) 0.5, "offset", (double) 0.5); + cs_r.set ("frequency", (double) 0.1); Gst.ControlSource cs_g = new Gst.Controller.LFOControlSource (); - cs_g.set ("frequency", (double) 0.27, "amplitude", (double) 0.5, "offset", (double) 0.5); + cs_g.set ("frequency", (double) 0.1); Gst.ControlSource cs_b = new Gst.Controller.LFOControlSource (); - cs_b.set ("frequency", (double) 0.13, "amplitude", (double) 0.5, "offset", (double) 0.5); + cs_b.set ("frequency", (double) 0.5); ((Gst.Object) textoverlay).add_control_binding (new Gst.Controller.ARGBControlBinding ((Gst.Object) textoverlay, "color", cs_a, cs_r, cs_g, cs_b)); - } } } diff --git a/src/VideoGrid.vala b/src/VideoGrid.vala index 4d2ff3c..7ffeaa4 100755 --- a/src/VideoGrid.vala +++ b/src/VideoGrid.vala @@ -116,7 +116,7 @@ namespace Niki { if (in_scale) { label_name.label = ((int)scale.get_value ()).to_string (); } - playerpage.playback.videomix.setvalue (index, val); + playerpage.playback.setvalue (index, val); if (!in_transition) { var selected_preset = videopresetlist.get_selected_preset (); if (selected_preset.is_default) { @@ -172,12 +172,12 @@ namespace Niki { var selected_preset = videopresetlist.get_selected_preset (); if (selected_preset != null) { for (int i = 0; i < scales.size; ++i) { - playerpage.playback.videomix.setvalue (i, selected_preset.getvalue (i)); + playerpage.playback.setvalue (i, selected_preset.getvalue (i)); } } } else { for (int i = 0; i < scales.size; ++i) { - playerpage.playback.videomix.setvalue (i, 0); + playerpage.playback.setvalue (i, 0); } } notify_current_preset (); @@ -242,7 +242,7 @@ namespace Niki { scale.set_value (target_level); notify_current_preset (); if (target_level == 0) { - playerpage.playback.videomix.setvalue (index, 0); + playerpage.playback.setvalue (index, 0); } } else { scale.set_value (scale.get_value () + (difference / 1.0)); diff --git a/src/VideoMix.vala b/src/VideoMix.vala index 5a85052..7bee671 100755 --- a/src/VideoMix.vala +++ b/src/VideoMix.vala @@ -24,27 +24,48 @@ namespace Niki { private dynamic Gst.Element videoqueue; public ClutterGst.VideoSink videosink; private dynamic Gst.Element videotee; - private dynamic Gst.Element gamma; + private dynamic Gst.Element elemen_gamma; private dynamic Gst.Element color_balance; public dynamic Gst.Element flip_filter; private dynamic Gst.Element coloreffects; private dynamic Gst.Element capsfilter; public dynamic Gst.Element videocrop; - private int saturation; + + private int _gamma; + public int gamma { + get { + return _gamma; + } + set { + _gamma = value; + elemen_gamma["gamma"] = (double) ((101.1 + (_gamma / 10)) / 100.0); + } + } + + private int _saturation; + public int saturation { + get { + return _saturation; + } + set { + _saturation = value; + color_balance["saturation"] = (double) ((100.0 + (_saturation / 10)) / 100.0); + } + } construct { videotee = Gst.ElementFactory.make ("tee", "tee"); videocrop = Gst.ElementFactory.make ("videocrop", "videocrop"); videoqueue = Gst.ElementFactory.make ("queue", "queue"); flip_filter = Gst.ElementFactory.make ("videoflip", "videoflip"); - gamma = Gst.ElementFactory.make ("gamma", "gamma"); + elemen_gamma = Gst.ElementFactory.make ("gamma", "gamma"); color_balance = Gst.ElementFactory.make ("videobalance", "videobalance"); coloreffects = Gst.ElementFactory.make ("coloreffects", "coloreffects"); capsfilter = Gst.ElementFactory.make ("capsfilter", "capsfilter"); videosink = new ClutterGst.VideoSink (); - add_many (videoqueue, videotee, capsfilter, videocrop, coloreffects, flip_filter, color_balance, gamma, videosink); + add_many (videoqueue, videotee, capsfilter, videocrop, coloreffects, flip_filter, color_balance, elemen_gamma, videosink); add_pad (new Gst.GhostPad ("sink", videotee.get_static_pad ("sink"))); - videoqueue.link_many (capsfilter, videocrop, coloreffects, flip_filter, color_balance, gamma, videosink); + videoqueue.link_many (capsfilter, videocrop, coloreffects, flip_filter, color_balance, elemen_gamma, videosink); Gst.Pad sinkpad = videoqueue.get_static_pad ("sink"); Gst.Pad pad = videotee.get_request_pad ("src_%u"); pad.link (sinkpad); @@ -52,13 +73,6 @@ namespace Niki { NikiApp.settings.changed["videorender-options"].connect (filetr_caps); filetr_caps (); coloreffect (); - videosink.pipeline_ready.connect (()=> { - videosink.list_channels ().foreach ((channel)=> { - if (channel.label == "SATURATION") { - videosink.set_value (channel, saturation); - } - }); - }); } private void filetr_caps () { @@ -89,32 +103,6 @@ namespace Niki { coloreffects["preset"] = NikiApp.settings.get_int ("coloreffects-options"); } - public void setvalue (int index, int valuescale) { - switch (index) { - case 0 : - gamma["gamma"] = (double) ((101.1 + valuescale) / 100.0); - break; - case 1 : - color_balance["brightness"] = (double) valuescale / 100.0; - break; - case 2 : - color_balance["contrast"] = (double) ((100.0 + valuescale) / 100.0); - break; - case 3 : - color_balance["saturation"] = (double) ((100.0 + valuescale) / 100.0); - saturation = valuescale * 10; - videosink.list_channels ().foreach ((channel)=> { - if (channel.label == "SATURATION") { - videosink.set_value (channel, saturation); - } - }); - break; - case 4 : - color_balance["hue"] = (double) valuescale / 100.0; - break; - } - } - public Gee.Collection get_presets () { var video_preset = new Gee.TreeSet (); foreach (string preset in NikiApp.settings_vf.get_strv ("custom-presets")) {