Skip to content

Commit

Permalink
new
Browse files Browse the repository at this point in the history
  • Loading branch information
torikulhabib committed Nov 21, 2021
1 parent e749246 commit 70245c5
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 98 deletions.
1 change: 0 additions & 1 deletion src/AudioMix.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
39 changes: 0 additions & 39 deletions src/CameraFlash.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,11 @@
* Authored by: torikulhabib <[email protected]>
*/

[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 ();
Expand All @@ -39,22 +33,13 @@ 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 () {
opacity *= 0.5;
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;
Expand Down Expand Up @@ -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;
}
}
}
95 changes: 93 additions & 2 deletions src/Player.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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")) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
9 changes: 6 additions & 3 deletions src/PreviewPopover.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -75,6 +76,8 @@ namespace Niki {
hide.connect (()=> {
playback.stop ();
});
var clear_content = new Clutter.Canvas ();

}

private void load_label () {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
});
Expand Down
18 changes: 7 additions & 11 deletions src/TextMix.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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));

}
}
}
8 changes: 4 additions & 4 deletions src/VideoGrid.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 ();
Expand Down Expand Up @@ -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));
Expand Down
Loading

0 comments on commit 70245c5

Please sign in to comment.