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

fix the waveform according to code review

parent 92a1aa80
......@@ -109,13 +109,6 @@ const MainWindow = new Lang.Class({
recordToolbar.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);
this._defineThemes();
......@@ -125,9 +118,15 @@ const MainWindow = new Lang.Class({
this.show_all();
},
_defineThemes : function() {
//let settings = Gtk.Settings.get_default();
_defineThemes: function() {
let settings = Gtk.Settings.get_default();
//settings.gtk_application_prefer_dark_theme = true;
},
resiz: function() {
//this.resize({ width:700,
//height: 480 });
log("YAY");
}
});
......@@ -181,7 +180,7 @@ const MainView = new Lang.Class({
//recordGrid.attach(this.recordTimeLabel, 20, 2, 3, 1);
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.connect ("value-changed", Lang.bind(this, this.setVolume));
//recordGrid.attach(this.recordVolume, 20, 4, 3, 1);
......@@ -230,7 +229,7 @@ const MainView = new Lang.Class({
playGrid.attach(this.progressScale, 20, 3, 3, 1);
/*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.connect("value-changed", Lang.bind(this, this.setVolume));
playGrid.attach(this.playVolume, 20, 4, 3, 1);*/
......@@ -255,6 +254,7 @@ const MainView = new Lang.Class({
onRecordStopClicked: function() {
this._record.stopRecording();
this.recordGrid.hide();
wave.resize();
},
setProgressScaleSensitive: function() {
......@@ -397,7 +397,7 @@ const MainView = new Lang.Class({
for (let i = this._startIdx; i <= this._endIdx; i++) {
this.rowGrid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL,
height_request: 36,
height_request: 45,
width_request: 400,
name: i.toString() });
this.rowGrid.set_orientation(Gtk.Orientation.HORIZONTAL);
......@@ -438,6 +438,7 @@ const MainView = new Lang.Class({
this._fileName = new Gtk.Label({ use_markup: true,
halign: Gtk.Align.START,
valign: Gtk.Align.START,
ellipsize: true,
xalign: 0,
width_chars: 40,
......@@ -451,12 +452,15 @@ const MainView = new Lang.Class({
this._fileName.show();
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._playLabelBox.show();
this.playDurationLabel = new Gtk.Label({ margin_left: 15,
halign: Gtk.Align.END,
valign: Gtk.Align.END,
margin_top: 5,
name: "PlayDurationLabel" });
this.fileDuration = this._formatTime(this._files[i].duration/Gst.SECOND);
this.playDurationLabel.label = this.fileDuration;
......@@ -464,23 +468,28 @@ const MainView = new Lang.Class({
this.playDurationLabel.show();
this.dividerLabel = new Gtk.Label({ halign: Gtk.Align.START,
name: "DividerLabel" });
name: "DividerLabel",
valign: Gtk.Align.END,
margin_top: 5 });
this.dividerLabel.label = "/";
this._playLabelBox.pack_start(this.dividerLabel, false, true, 0);
this.dividerLabel.hide();
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._playLabelBox.pack_start(this.playTimeLabel, false, true, 0);
this.playTimeLabel.hide();
this.waveFormGrid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL,
height_request: 36,
height_request: 45,
width_request: 350,
valign: Gtk.Align.FILL,
name: "WaveFormGrid" });
this.waveFormGrid.set_no_show_all(true);
this.rowGrid.add(this.waveFormGrid);
this.rowGrid.attach(this.waveFormGrid, 9, 1, 1, 2);
this.waveFormGrid.show();
......@@ -490,7 +499,7 @@ const MainView = new Lang.Class({
icon_size: Gtk.IconSize.BUTTON,
opacity: 1,
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._boxInfo = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL });
......@@ -523,7 +532,7 @@ const MainView = new Lang.Class({
opacity: 1,
name: "DeleteToolbar" });
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._groupDelete = new Gtk.ToolItem({ child: this._boxDelete });
......
......@@ -136,7 +136,7 @@ const _TENTH_SEC = 100000000;
case Gst.MessageType.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;
case Gst.MessageType.DURATION:
......
......@@ -224,6 +224,7 @@ const Record = new Lang.Class({
log("level");
let p = null;
let peakVal = 0;
let val = 0;
let st = s.get_value("timestamp");
log(st);
let dur = s.get_value("duration");
......@@ -234,10 +235,10 @@ const Record = new Lang.Class({
log("peakVal" + peakVal);
if (peakVal) {
let val = peakVal.get_nth(0);
let valBase = (val / 20);
let value = Math.pow(10, valBase);
this.peak = value/3.375;
log("record wave height" + value);
log("val" + val);
let value = Math.pow(val, 3);
this.peak = value * 0.001;
log("wave height" + this.peak);
}
}
}
......@@ -257,9 +258,9 @@ const Record = new Lang.Class({
},
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);
this.srcElement.set_volume(GstAudio.StreamVolumeFormat.CUBIC, level);
this.srcElement.set_volume(GstAudio.StreamVolumeFormat.LINEAR, level);
}
});
......
......@@ -38,6 +38,7 @@ const MainWindow = imports.mainWindow;
const peaks = [];
const INTERVAL = 100000000;
const pauseVal = 10;
const waveSamples = 40;
const WaveType = {
RECORD: 0,
......@@ -59,17 +60,21 @@ const WaveForm = new Lang.Class({
this.waveType = WaveType.RECORD;
}
this.count = 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) {
let gridWidth = MainWindow.groupGrid.get_allocated_width();
gridWidth = MainWindow.groupGrid.get_allocated_width();
log("gridWidth " + gridWidth);
let drawingWidth = gridWidth * 0.75;
drawingWidth = gridWidth * 0.75;
this.drawing.set_size_request(drawingWidth, 36);
this._grid.attach(this.drawing, 2, 0, 3, 2);
} else {
this.drawing.set_size_request(200, 36);
this.drawing.set_size_request(350, 36);
this._grid.add(this.drawing);
}
......@@ -117,6 +122,8 @@ const WaveForm = new Lang.Class({
if (s.has_name("level")) {
let p = null;
let peakVal = 0;
let peaknumber = 0;
let value = 0;
let st = s.get_value("timestamp");
log(st);
let dur = s.get_value("duration");
......@@ -127,10 +134,14 @@ const WaveForm = new Lang.Class({
if (peakVal) {
let val = peakVal.get_nth(0);
let valBase = (val / 20);
let value = Math.pow(10, valBase);
let peaknumber = value/3.375;
if (val >= 0) {
value = Math.pow(val, 1/3);
peaknumber = value * 0.1;
log("wave height" + value);
} else {
peaknumber = 0;
}
peaks.push(peaknumber);
}
}
......@@ -171,43 +182,60 @@ const WaveForm = new Lang.Class({
log("continue drawing " + peaks.length);
}
}
let w = this.drawing.get_allocated_width();
log("w " + w);
let h = this.drawing.get_allocated_height();
log("h" + h)
let length = this.nSamples;
log("length " + this.nSamples);
let waveheight = h;
let pixelsPerSample = w/40;
let pixelsPerSample = w/waveSamples;
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.0, 0.2, 0.54, 0.47, 0.22);
let base;
cr.setLineWidth(1);
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 (peaks[i] != null) {
if (this.tick >= 40 && peaks[idx] != null) {
idx = this.count + i + 1;
log("value of the index for peaks " + idx);
if (this.tick < waveSamples) {
base = start + i;
cr.lineTo((base * pixelsPerSample), (h - (peaks[i] * waveheight)));
} else {
idx = i;
cr.lineTo((start * pixelsPerSample), (h - (peaks[i] * waveheight)));
}
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);
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.strokePreserve();
......@@ -230,7 +258,6 @@ const WaveForm = new Lang.Class({
if (this.tick < this.playTime) {//&& this.tick < this.nSamples) { should be somewhere else
this.tick += 1;
this.count += 1;
log("tick value" + this.tick);
}
......@@ -249,16 +276,9 @@ const WaveForm = new Lang.Class({
log("error");
}
if (this.tick < this.recordTime) {//&& this.tick < this.nSamples) { should be somewhere else
this.tick += 1;
this.count += 1;
log("rec tick value" + this.tick);
}
if (lastTime != this.recordTime) {
this.drawing.queue_draw();
log("rec drawing queued");
}
}
return true;
},
......@@ -269,5 +289,9 @@ const WaveForm = new Lang.Class({
this.count = 0;
peaks.length = 0;
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