Commit 8c2f5619 authored by Meg Ford's avatar Meg Ford

fix the waveform according to code review

parent 92a1aa80
...@@ -108,13 +108,6 @@ const MainWindow = new Lang.Class({ ...@@ -108,13 +108,6 @@ const MainWindow = new Lang.Class({
recordToolbar.get_style_context().add_class('header'); recordToolbar.get_style_context().add_class('header');
recordToolbar.show(); recordToolbar.show();
recordButton.show(); recordButton.show();
let preferencesButton = new Gtk.Button();
let preferencesImage = Gtk.Image.new_from_icon_name("emblem-system-symbolic", Gtk.IconSize.BUTTON);
preferencesButton.image = preferencesImage;
//add code to choose codec
header.pack_end(preferencesButton);
grid.add(view); grid.add(view);
...@@ -125,10 +118,16 @@ const MainWindow = new Lang.Class({ ...@@ -125,10 +118,16 @@ const MainWindow = new Lang.Class({
this.show_all(); this.show_all();
}, },
_defineThemes : function() { _defineThemes: function() {
//let settings = Gtk.Settings.get_default(); let settings = Gtk.Settings.get_default();
//settings.gtk_application_prefer_dark_theme = true; //settings.gtk_application_prefer_dark_theme = true;
} },
resiz: function() {
//this.resize({ width:700,
//height: 480 });
log("YAY");
}
}); });
const MainView = new Lang.Class({ const MainView = new Lang.Class({
...@@ -181,7 +180,7 @@ const MainView = new Lang.Class({ ...@@ -181,7 +180,7 @@ const MainView = new Lang.Class({
//recordGrid.attach(this.recordTimeLabel, 20, 2, 3, 1); //recordGrid.attach(this.recordTimeLabel, 20, 2, 3, 1);
this.recordVolume = new Gtk.VolumeButton(); this.recordVolume = new Gtk.VolumeButton();
this.recordRange = Gtk.Adjustment.new(0.2, 0, 3.375, 0.05, 0.0, 0.0); this.recordRange = Gtk.Adjustment.new(0.2, 0, 1.0, 0.05, 0.0, 0.0);
this.recordVolume.set_adjustment(this.recordRange); this.recordVolume.set_adjustment(this.recordRange);
this.recordVolume.connect ("value-changed", Lang.bind(this, this.setVolume)); this.recordVolume.connect ("value-changed", Lang.bind(this, this.setVolume));
//recordGrid.attach(this.recordVolume, 20, 4, 3, 1); //recordGrid.attach(this.recordVolume, 20, 4, 3, 1);
...@@ -230,7 +229,7 @@ const MainView = new Lang.Class({ ...@@ -230,7 +229,7 @@ const MainView = new Lang.Class({
playGrid.attach(this.progressScale, 20, 3, 3, 1); playGrid.attach(this.progressScale, 20, 3, 3, 1);
/*this.playVolume = new Gtk.VolumeButton(); /*this.playVolume = new Gtk.VolumeButton();
this.range = Gtk.Adjustment.new(0.5, 0, 3.375, 0.15, 0.0, 0.0); this.range = Gtk.Adjustment.new(0.90, 0, 1.0, 0.05, 0.0, 0.0);
this.playVolume.set_adjustment(this.range); this.playVolume.set_adjustment(this.range);
this.playVolume.connect("value-changed", Lang.bind(this, this.setVolume)); this.playVolume.connect("value-changed", Lang.bind(this, this.setVolume));
playGrid.attach(this.playVolume, 20, 4, 3, 1);*/ playGrid.attach(this.playVolume, 20, 4, 3, 1);*/
...@@ -255,6 +254,7 @@ const MainView = new Lang.Class({ ...@@ -255,6 +254,7 @@ const MainView = new Lang.Class({
onRecordStopClicked: function() { onRecordStopClicked: function() {
this._record.stopRecording(); this._record.stopRecording();
this.recordGrid.hide(); this.recordGrid.hide();
wave.resize();
}, },
setProgressScaleSensitive: function() { setProgressScaleSensitive: function() {
...@@ -397,7 +397,7 @@ const MainView = new Lang.Class({ ...@@ -397,7 +397,7 @@ const MainView = new Lang.Class({
for (let i = this._startIdx; i <= this._endIdx; i++) { for (let i = this._startIdx; i <= this._endIdx; i++) {
this.rowGrid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL, this.rowGrid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL,
height_request: 36, height_request: 45,
width_request: 400, width_request: 400,
name: i.toString() }); name: i.toString() });
this.rowGrid.set_orientation(Gtk.Orientation.HORIZONTAL); this.rowGrid.set_orientation(Gtk.Orientation.HORIZONTAL);
...@@ -438,6 +438,7 @@ const MainView = new Lang.Class({ ...@@ -438,6 +438,7 @@ const MainView = new Lang.Class({
this._fileName = new Gtk.Label({ use_markup: true, this._fileName = new Gtk.Label({ use_markup: true,
halign: Gtk.Align.START, halign: Gtk.Align.START,
valign: Gtk.Align.START,
ellipsize: true, ellipsize: true,
xalign: 0, xalign: 0,
width_chars: 40, width_chars: 40,
...@@ -451,12 +452,15 @@ const MainView = new Lang.Class({ ...@@ -451,12 +452,15 @@ const MainView = new Lang.Class({
this._fileName.show(); this._fileName.show();
this._playLabelBox = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL, this._playLabelBox = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL,
name: "PlayLabelBox" }); name: "PlayLabelBox",
height_request: 36 });
this.rowGrid.attach(this._playLabelBox, 2, 1, 1, 1); this.rowGrid.attach(this._playLabelBox, 2, 1, 1, 1);
this._playLabelBox.show(); this._playLabelBox.show();
this.playDurationLabel = new Gtk.Label({ margin_left: 15, this.playDurationLabel = new Gtk.Label({ margin_left: 15,
halign: Gtk.Align.END, halign: Gtk.Align.END,
valign: Gtk.Align.END,
margin_top: 5,
name: "PlayDurationLabel" }); name: "PlayDurationLabel" });
this.fileDuration = this._formatTime(this._files[i].duration/Gst.SECOND); this.fileDuration = this._formatTime(this._files[i].duration/Gst.SECOND);
this.playDurationLabel.label = this.fileDuration; this.playDurationLabel.label = this.fileDuration;
...@@ -464,23 +468,28 @@ const MainView = new Lang.Class({ ...@@ -464,23 +468,28 @@ const MainView = new Lang.Class({
this.playDurationLabel.show(); this.playDurationLabel.show();
this.dividerLabel = new Gtk.Label({ halign: Gtk.Align.START, this.dividerLabel = new Gtk.Label({ halign: Gtk.Align.START,
name: "DividerLabel" }); name: "DividerLabel",
valign: Gtk.Align.END,
margin_top: 5 });
this.dividerLabel.label = "/"; this.dividerLabel.label = "/";
this._playLabelBox.pack_start(this.dividerLabel, false, true, 0); this._playLabelBox.pack_start(this.dividerLabel, false, true, 0);
this.dividerLabel.hide(); this.dividerLabel.hide();
this.playTimeLabel = new Gtk.Label({ halign: Gtk.Align.START, this.playTimeLabel = new Gtk.Label({ halign: Gtk.Align.START,
name: "PlayTimeLabel" }); name: "PlayTimeLabel",
valign: Gtk.Align.END,
margin_top: 5 });
this.playTimeLabel.label = "0:00"; this.playTimeLabel.label = "0:00";
this._playLabelBox.pack_start(this.playTimeLabel, false, true, 0); this._playLabelBox.pack_start(this.playTimeLabel, false, true, 0);
this.playTimeLabel.hide(); this.playTimeLabel.hide();
this.waveFormGrid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL, this.waveFormGrid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL,
height_request: 36, height_request: 45,
width_request: 350, width_request: 350,
valign: Gtk.Align.FILL,
name: "WaveFormGrid" }); name: "WaveFormGrid" });
this.waveFormGrid.set_no_show_all(true); this.waveFormGrid.set_no_show_all(true);
this.rowGrid.add(this.waveFormGrid); this.rowGrid.attach(this.waveFormGrid, 9, 1, 1, 2);
this.waveFormGrid.show(); this.waveFormGrid.show();
...@@ -490,7 +499,7 @@ const MainView = new Lang.Class({ ...@@ -490,7 +499,7 @@ const MainView = new Lang.Class({
icon_size: Gtk.IconSize.BUTTON, icon_size: Gtk.IconSize.BUTTON,
opacity: 1, opacity: 1,
name: "InfoToolbar" }); name: "InfoToolbar" });
this.rowGrid.attach(this.widgetInfo, 4, 0, 1, 2); this.rowGrid.attach(this.widgetInfo, 10, 0, 1, 2);
this.widgetInfo.get_style_context().add_class('toolbar'); this.widgetInfo.get_style_context().add_class('toolbar');
this._boxInfo = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL }); this._boxInfo = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL });
...@@ -523,7 +532,7 @@ const MainView = new Lang.Class({ ...@@ -523,7 +532,7 @@ const MainView = new Lang.Class({
opacity: 1, opacity: 1,
name: "DeleteToolbar" }); name: "DeleteToolbar" });
this.widgetDelete.get_style_context().add_class('toolbarEnd'); this.widgetDelete.get_style_context().add_class('toolbarEnd');
this.rowGrid.attach(this.widgetDelete, 5, 0, 1, 2); this.rowGrid.attach(this.widgetDelete, 11, 0, 1, 2);
this._boxDelete = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL }); this._boxDelete = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL });
this._groupDelete = new Gtk.ToolItem({ child: this._boxDelete }); this._groupDelete = new Gtk.ToolItem({ child: this._boxDelete });
......
...@@ -95,7 +95,7 @@ const _TENTH_SEC = 100000000; ...@@ -95,7 +95,7 @@ const _TENTH_SEC = 100000000;
this.baseTime = this.absoluteTime; this.baseTime = this.absoluteTime;
log("pause"); log("pause");
if (this.timeout) { if (this.timeout) {
GLib.source_remove(this.timeout); GLib.source_remove(this.timeout);
this.timeout = null; this.timeout = null;
} }
}, },
...@@ -136,7 +136,7 @@ const _TENTH_SEC = 100000000; ...@@ -136,7 +136,7 @@ const _TENTH_SEC = 100000000;
case Gst.MessageType.ERROR: case Gst.MessageType.ERROR:
log("Error :" + e.parse_error()); log("Error :" + e.parse_error());
this._showErrorDialog(_("Error :" + e.parse_error())); this._showErrorDialog(_("Error :" + e.parse_error())); //should I only show for specific error messages
break; break;
case Gst.MessageType.DURATION: case Gst.MessageType.DURATION:
...@@ -157,7 +157,7 @@ const _TENTH_SEC = 100000000; ...@@ -157,7 +157,7 @@ const _TENTH_SEC = 100000000;
this.pausePlaying(); this.pausePlaying();
break; break;
case Gst.MessageType.NEW_CLOCK: case Gst.MessageType.NEW_CLOCK:
if (this.playState == PipelineStates.PAUSED) { if (this.playState == PipelineStates.PAUSED) {
this.clock = this.play.get_clock(); this.clock = this.play.get_clock();
this.startPlaying(); this.startPlaying();
......
...@@ -224,6 +224,7 @@ const Record = new Lang.Class({ ...@@ -224,6 +224,7 @@ const Record = new Lang.Class({
log("level"); log("level");
let p = null; let p = null;
let peakVal = 0; let peakVal = 0;
let val = 0;
let st = s.get_value("timestamp"); let st = s.get_value("timestamp");
log(st); log(st);
let dur = s.get_value("duration"); let dur = s.get_value("duration");
...@@ -232,13 +233,13 @@ const Record = new Lang.Class({ ...@@ -232,13 +233,13 @@ const Record = new Lang.Class({
log(runTime); log(runTime);
peakVal = s.get_value("peak"); peakVal = s.get_value("peak");
log("peakVal" + peakVal); log("peakVal" + peakVal);
if (peakVal) { if (peakVal) {
let val = peakVal.get_nth(0); let val = peakVal.get_nth(0);
let valBase = (val / 20); log("val" + val);
let value = Math.pow(10, valBase); let value = Math.pow(val, 3);
this.peak = value/3.375; this.peak = value * 0.001;
log("record wave height" + value); log("wave height" + this.peak);
} }
} }
} }
break; break;
...@@ -257,9 +258,9 @@ const Record = new Lang.Class({ ...@@ -257,9 +258,9 @@ const Record = new Lang.Class({
}, },
setVolume: function(value) { setVolume: function(value) {
let level = this.srcElement.convert_volume(GstAudio.StreamVolumeFormat.LINEAR, GstAudio.StreamVolumeFormat.CUBIC, value); let level = this.srcElement.convert_volume(GstAudio.StreamVolumeFormat.CUBIC, GstAudio.StreamVolumeFormat.LINEAR, value);
log(level); log(level);
this.srcElement.set_volume(GstAudio.StreamVolumeFormat.CUBIC, level); this.srcElement.set_volume(GstAudio.StreamVolumeFormat.LINEAR, level);
} }
}); });
......
...@@ -38,6 +38,7 @@ const MainWindow = imports.mainWindow; ...@@ -38,6 +38,7 @@ const MainWindow = imports.mainWindow;
const peaks = []; const peaks = [];
const INTERVAL = 100000000; const INTERVAL = 100000000;
const pauseVal = 10; const pauseVal = 10;
const waveSamples = 40;
const WaveType = { const WaveType = {
RECORD: 0, RECORD: 0,
...@@ -59,17 +60,21 @@ const WaveForm = new Lang.Class({ ...@@ -59,17 +60,21 @@ const WaveForm = new Lang.Class({
this.waveType = WaveType.RECORD; this.waveType = WaveType.RECORD;
} }
this.count = 0;
this.tick = 0; this.tick = 0;
this.drawing = Gtk.DrawingArea.new(); let gridWidth = 0;
let drawingWidth = 0;
let drawingHeight = 0;
this.drawing = Gtk.DrawingArea.new({ height_request: 45,
width_request: 350,
valign: Gtk.Align.FILL });
if (this.waveType == WaveType.RECORD) { if (this.waveType == WaveType.RECORD) {
let gridWidth = MainWindow.groupGrid.get_allocated_width(); gridWidth = MainWindow.groupGrid.get_allocated_width();
log("gridWidth " + gridWidth); log("gridWidth " + gridWidth);
let drawingWidth = gridWidth * 0.75; drawingWidth = gridWidth * 0.75;
this.drawing.set_size_request(drawingWidth, 36); this.drawing.set_size_request(drawingWidth, 36);
this._grid.attach(this.drawing, 2, 0, 3, 2); this._grid.attach(this.drawing, 2, 0, 3, 2);
} else { } else {
this.drawing.set_size_request(200, 36); this.drawing.set_size_request(350, 36);
this._grid.add(this.drawing); this._grid.add(this.drawing);
} }
...@@ -117,6 +122,8 @@ const WaveForm = new Lang.Class({ ...@@ -117,6 +122,8 @@ const WaveForm = new Lang.Class({
if (s.has_name("level")) { if (s.has_name("level")) {
let p = null; let p = null;
let peakVal = 0; let peakVal = 0;
let peaknumber = 0;
let value = 0;
let st = s.get_value("timestamp"); let st = s.get_value("timestamp");
log(st); log(st);
let dur = s.get_value("duration"); let dur = s.get_value("duration");
...@@ -127,10 +134,14 @@ const WaveForm = new Lang.Class({ ...@@ -127,10 +134,14 @@ const WaveForm = new Lang.Class({
if (peakVal) { if (peakVal) {
let val = peakVal.get_nth(0); let val = peakVal.get_nth(0);
let valBase = (val / 20);
let value = Math.pow(10, valBase); if (val >= 0) {
let peaknumber = value/3.375; value = Math.pow(val, 1/3);
log("wave height" + value); peaknumber = value * 0.1;
log("wave height" + value);
} else {
peaknumber = 0;
}
peaks.push(peaknumber); peaks.push(peaknumber);
} }
} }
...@@ -171,43 +182,60 @@ const WaveForm = new Lang.Class({ ...@@ -171,43 +182,60 @@ const WaveForm = new Lang.Class({
log("continue drawing " + peaks.length); log("continue drawing " + peaks.length);
} }
} }
let w = this.drawing.get_allocated_width(); let w = this.drawing.get_allocated_width();
log("w " + w); log("w " + w);
let h = this.drawing.get_allocated_height(); let h = this.drawing.get_allocated_height();
log("h" + h)
let length = this.nSamples; let length = this.nSamples;
log("length " + this.nSamples); log("length " + this.nSamples);
let waveheight = h; let waveheight = h;
let pixelsPerSample = w/40; let pixelsPerSample = w/waveSamples;
log("pixelsPerSample " + pixelsPerSample); log("pixelsPerSample " + pixelsPerSample);
let idx;
let gradient = new Cairo.LinearGradient(0, 0, this.tick * pixelsPerSample, peaks[idx] * waveheight); let start = 0;
let i = 0;
if (this.tick < waveSamples) {
start = (waveSamples - this.tick);
}
if (this.tick >= waveSamples) {
let num = Math.floor(this.tick / waveSamples);
log(num);
let add = this.tick % (num * waveSamples);
log("add" + add);
i += add;
}
log("set i" + i);
cr.moveTo(start * pixelsPerSample, h);
let gradient = new Cairo.LinearGradient(0, 0, w , h);
gradient.addColorStopRGBA(0.75, 0.0, 0.72, 0.64, 0.35); gradient.addColorStopRGBA(0.75, 0.0, 0.72, 0.64, 0.35);
gradient.addColorStopRGBA(0.0, 0.2, 0.54, 0.47, 0.22); gradient.addColorStopRGBA(0.0, 0.2, 0.54, 0.47, 0.22);
let base;
cr.setLineWidth(1); cr.setLineWidth(1);
cr.setSourceRGBA(0.0, 185, 161, 255); cr.setSourceRGBA(0.0, 185, 161, 255);
cr.moveTo(0, h);
for(let i = 0; i <= this.tick; i++) { for(i; i < this.tick; i++) {
if (this.tick >= 40 && peaks[idx] != null) {
idx = this.count + i + 1;
log("value of the index for peaks " + idx);
} else {
idx = i;
}
if (peaks[idx] != null) {
cr.lineTo(i * pixelsPerSample, peaks[idx] * waveheight);
log("current base value for x co-ordinate " + this.tick);
log("peak height " + peaks[idx]);
log("array length " + peaks.length);
log("array index value " + idx);
if (peaks[i] != null) {
if (this.tick < waveSamples) {
base = start + i;
cr.lineTo((base * pixelsPerSample), (h - (peaks[i] * waveheight)));
} else {
cr.lineTo((start * pixelsPerSample), (h - (peaks[i] * waveheight)));
}
log("current base value for x co-ordinate " + this.tick);
log("peak height " + (h - (peaks[i] * waveheight)));
log("h " + h);
log("array index value " + peaks[i] * waveheight);
log("start " + start);
} }
if (this.tick > waveSamples)
start += 1;
} }
cr.lineTo(this.tick * pixelsPerSample, h); cr.lineTo(w, h);
cr.closePath(); cr.closePath();
cr.strokePreserve(); cr.strokePreserve();
...@@ -230,7 +258,6 @@ const WaveForm = new Lang.Class({ ...@@ -230,7 +258,6 @@ const WaveForm = new Lang.Class({
if (this.tick < this.playTime) {//&& this.tick < this.nSamples) { should be somewhere else if (this.tick < this.playTime) {//&& this.tick < this.nSamples) { should be somewhere else
this.tick += 1; this.tick += 1;
this.count += 1;
log("tick value" + this.tick); log("tick value" + this.tick);
} }
...@@ -249,16 +276,9 @@ const WaveForm = new Lang.Class({ ...@@ -249,16 +276,9 @@ const WaveForm = new Lang.Class({
log("error"); log("error");
} }
if (this.tick < this.recordTime) {//&& this.tick < this.nSamples) { should be somewhere else this.tick += 1;
this.tick += 1; log("rec tick value" + this.tick);
this.count += 1; this.drawing.queue_draw();
log("rec tick value" + this.tick);
}
if (lastTime != this.recordTime) {
this.drawing.queue_draw();
log("rec drawing queued");
}
} }
return true; return true;
}, },
...@@ -269,5 +289,9 @@ const WaveForm = new Lang.Class({ ...@@ -269,5 +289,9 @@ const WaveForm = new Lang.Class({
this.count = 0; this.count = 0;
peaks.length = 0; peaks.length = 0;
this.drawing.destroy(); this.drawing.destroy();
} },
resize: function() {
MainWindow.MainWindow.resiz();
}
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment