Codebase list gnome-sound-recorder / 4a1cb88
properly handle recorder/recording duration - default to 0 nanoseconds - make use of Date to get miliseconds easily - use tnum font feature Bilal Elmoussaoui 3 years ago
7 changed file(s) with 27 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
2828 <property name="visible">True</property>
2929 <property name="can_focus">False</property>
3030 <property name="margin_top">18</property>
31 <property name="use_markup">True</property>
32 <attributes>
33 <attribute name="font-features" value="tnum=1"/>
34 </attributes>
3135 <style>
3236 <class name="dim-label"/>
3337 <class name="recorder-time-label"/>
3030 <property name="visible">True</property>
3131 <property name="can_focus">False</property>
3232 <property name="halign">end</property>
33 <property name="use_markup">True</property>
34 <attributes>
35 <attribute name="font-features" value="tnum=1"/>
36 </attributes>
3337 </object>
3438 <packing>
3539 <property name="pack_type">end</property>
6262 Properties: {
6363 'duration': GObject.ParamSpec.int(
6464 'duration',
65 'Recording Duration', 'Recording duration in seconds',
65 'Recording Duration', 'Recording duration in nanoseconds',
6666 GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT,
6767 0, GLib.MAXINT16, 0),
6868 'current-peak': GObject.ParamSpec.float(
130130 this.timeout = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 100, () => {
131131 const pos = this.pipeline.query_position(Gst.Format.TIME)[1];
132132 if (pos > 0)
133 this.duration = pos / Gst.SECOND;
133 this.duration = pos;
134134 return true;
135135 });
136136 }
146146
147147 stop() {
148148 this.state = Gst.State.NULL;
149
149 this.duration = 0;
150150 if (this.timeout) {
151151 GLib.source_remove(this.timeout);
152152 this.timeout = null;
3434
3535 this.recorder.bind_property('current-peak', this.waveform, 'peak', GObject.BindingFlags.SYNC_CREATE | GObject.BindingFlags.DEFAULT);
3636 this.recorder.connect('notify::duration', _recorder => {
37 this._recorderTime.label = formatTime(_recorder.duration);
37 this._recorderTime.set_markup(formatTime(_recorder.duration));
3838 });
3939
4040
1111 Properties: {
1212 'duration': GObject.ParamSpec.int(
1313 'duration',
14 'Recording Duration', 'Recording duration in seconds',
14 'Recording Duration', 'Recording duration in nanoseconds',
1515 GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT,
1616 0, GLib.MAXINT16, 0),
1717 'name': GObject.ParamSpec.string(
4646 discoverer.start();
4747 discoverer.connect('discovered', (_discoverer, audioInfo) => {
4848 this._duration = audioInfo.get_duration();
49
4950 this.notify('duration');
5051 });
5152
00 /* exported Row */
1 const { Gdk, Gio, GObject, Gst, Gtk } = imports.gi;
1 const { Gdk, Gio, GObject, Gtk } = imports.gi;
22 const { displayDateTime, formatTime } = imports.utils;
33 const { WaveForm, WaveType } = imports.waveform;
44
153153
154154 // Force LTR, we don't want reverse hh:mm::ss
155155 this._duration.direction = Gtk.TextDirection.LTR;
156 this._duration.label = formatTime(recording.duration / Gst.SECOND);
156 this._duration.markup = formatTime(recording.duration);
157157 recording.connect('notify::duration', () => {
158 this._duration.label = formatTime(recording.duration / Gst.SECOND);
158 this._duration.label = formatTime(recording.duration);
159159 });
160160 }
161161
1717 *
1818 */
1919 const Gettext = imports.gettext;
20 const GLib = imports.gi.GLib;
20 const { GLib, Gst } = imports.gi;
2121
22 var formatTime = totalSeconds => {
23 totalSeconds = Math.floor(totalSeconds);
24 const hours = parseInt(totalSeconds / Math.pow(60, 2)).toString();
25 const minutes = (parseInt(totalSeconds / 60) % 60).toString();
26 const seconds = parseInt(totalSeconds % 60).toString();
22 var formatTime = nanoSeconds => {
23 const time = new Date(0, 0, 0, 0, 0, 0, parseInt(nanoSeconds / Gst.MSECOND));
2724
28 return `${hours.padStart(2, '0')}∶${minutes.padStart(2, '0')}∶${seconds.padStart(2, '0')}`;
25 const miliseconds = time.getMilliseconds().toString().padStart(2, '0').substring(0, 2);
26 const seconds = time.getSeconds().toString().padStart(2, '0');
27 const minutes = time.getMinutes().toString().padStart(2, '0');
28 const hours = time.getHours().toString().padStart(2, '0');
29
30 // eslint-disable-next-line no-irregular-whitespace
31 return `${hours} ∶ ${minutes} ∶ ${seconds} . <small>${miliseconds}</small>`;
2932 };
3033
3134 var displayDateTime = time => {