Commit c8a155ec authored by Meg Ford's avatar Meg Ford

code cleanup

parent 8528708d
......@@ -11,6 +11,32 @@
<description>Window position (x and y).</description>
</key>
</schema>
<schema id="org.gnome.SoundRecorder.Application.encoding-settings" path="/org/gnome/SoundRecorder/Application/encoding-settings/">
<key name="media-type" type="s">
<default>'audio/x-vorbis'</default>
<summary>Preferred media type for encoding audio when recording</summary>
<description>Preferred media type for encoding audio when recording. 'audio/x-vorbis' for Ogg Vorbis, or 'audio/mpeg' for MP3, for example. This is not a MIME type.</description>
</key>
<key name="media-type-presets" type="a{ss}">
<default>[]</default>
<summary>Maps media types to audio encoder preset names.</summary>
<description>Maps media types to audio encoder preset names. If there is no mapping for a media type, the default encoder settings will be used.</description>
</key>
</schema>
<schema id="org.gnome.SoundRecorder.Application.play" path="/org/gnome/SoundRecorder/Application/play/">
<key name="volume" type="d">
<default>0.75</default>
<summary>Volume level</summary>
<description>Volume level.</description>
</key>
</schema>
<schema id="org.gnome.SoundRecorder.Application.record" path="/org/gnome/SoundRecorder/Application/record/">
<key name="volume" type="d">
<default>0.75</default>
<summary>Volume level</summary>
<description>Volume level.</description>
</key>
</schema>
</schemalist>
......@@ -29,15 +29,18 @@ const Gst = imports.gi.Gst;
const GstPbutils = imports.gi.GstPbutils;
const Mainloop = imports.mainloop;
const MainWindow = imports.mainWindow;
const Preferences = imports.preferences;
const containerProfileMap = {
OGG: "application/ogg",
ID3: "application/x-id3",
MP3: "application/x-id3",
MP4: "video/quicktime,variant=(string)iso"
};
const audioCodecMap = {
FLAC: "audio/x-flac",
ID3: "audio/mpeg,mpegversion=(int)1,layer=(int)3",
MP3: "audio/mpeg,mpegversion=(int)1,layer=(int)3",
MP4: "audio/mpeg,mpegversion=(int)4",
OPUS: "audio/x-opus",
OGG_VORBIS: "audio/x-vorbis"
......@@ -47,7 +50,7 @@ const comboBoxMap = {
OGG_VORBIS: 0,
OPUS: 1,
FLAC: 2,
ID3: 3,
MP3: 3,
MP4: 4
};
......@@ -57,8 +60,8 @@ const AudioProfile = new Lang.Class({
assignProfile: function(profileName){
if (profileName)
this._profileName = profileName;
else
this._profileName = 0;
else
this._profileName = comboBoxMap.OGG_VORBIS;
log("profileName" + this._profileName);
this._values = [];
switch(this._profileName) {
......@@ -72,14 +75,13 @@ const AudioProfile = new Lang.Class({
case comboBoxMap.FLAC:
this._values.push({ container: containerProfileMap.OGG, audio: audioCodecMap.FLAC });
break;
case comboBoxMap.ID3:
this._values.push({ container: containerProfileMap.MP3, audio: audioCodecMap.ID3 });
case comboBoxMap.MP3:
this._values.push({ container: containerProfileMap.MP3, audio: audioCodecMap.MP3 });
break;
case comboBoxMap.MP4:
this._values.push({ container: containerProfileMap.AAC, audio: audioCodecMap.MP4 });
break;
default:
this._values.push({ container: containerProfileMap.OGG, audio: audioCodecMap.OGG_VORBIS });
break;
}
},
......
......@@ -59,11 +59,7 @@ const FileUtil = new Lang.Class({
},
_deleteFileCallback: function(obj, res) {
this._deleted = obj.delete_finish(res);
//this._list = new Listview.Listview();
//this._list.refreshListview();
//MainWindow.offsetController.resetOffset();
//MainWindow.view.listBoxAdd();
this._deleted = obj.delete_finish(res);
},
getDirPath: function() {
......
......@@ -27,8 +27,8 @@ const _ = imports.gettext.gettext;
const C_ = imports.gettext.pgettext;
const Lang = imports.lang;
const MainWindow = imports.mainWindow;
const FileUtil = imports.fileUtil;
const MainWindow = imports.mainWindow;
const _FILE_NAME_ENTRY_TIMEOUT = 600;
......
......@@ -317,8 +317,8 @@ const Listview = new Lang.Class({
this.file.mediaType = mediaTypeMap.OGG_VORBIS;
else if (audioCaps.is_subset(Gst.Caps.from_string(AudioProfile.audioCodecMap.OPUS)))
this.file.mediaType = mediaTypeMap.OPUS;
} else if (containerCaps.is_subset(Gst.Caps.from_string(AudioProfile.containerProfileMap.ID3))) {
if (audioCaps.is_subset(Gst.Caps.from_string(AudioProfile.audioCodecMap.ID3)))
} else if (containerCaps.is_subset(Gst.Caps.from_string(AudioProfile.containerProfileMap.MP3))) {
if (audioCaps.is_subset(Gst.Caps.from_string(AudioProfile.audioCodecMap.MP3)))
this.file.mediaType = mediaTypeMap.MP3;
} else if (containerCaps.is_subset(Gst.Caps.from_string(AudioProfile.containerProfileMap.MP4))) {
if (audioCaps.is_subset(Gst.Caps.from_string(AudioProfile.audioCodecMap.MP4)))
......
......@@ -33,9 +33,11 @@ const FileUtil = imports.fileUtil;
const Info = imports.info;
const Listview = imports.listview;
const Play = imports.play;
const Preferences = imports.preferences;
const Record = imports.record;
const Waveform = imports.waveform;
let activeProfile = null;
let audioProfile = null;
let fileUtil = null;
let grid = null;
......@@ -44,11 +46,13 @@ let list = null;
let offsetController = null;
let path = null;
let play = null;
let recordPipeline = null;
let recordButton = null;
let selectable = null;
let setVisibleID = null;
let view = null;
let volumeValue = [];
let wave = null;
let recordPipeline = null;
let recordButton = null;
const ActiveArea = {
RECORD: 0,
......@@ -202,27 +206,34 @@ const MainView = new Lang.Class({
return true;
},
presetVolume: function(source, vol) {
if (source == ActiveArea.PLAY)
volumeValue[0].play = vol;
else
volumeValue[0].record = vol;
},
setVolume: function() {
let volumeValue;
if (this.setVisibleID == ActiveArea.PLAY) {
volumeValue = this.playVolume.get_value();
MainWindow.play.setVolume(volumeValue);
} else if (this.setVisibleID == ActiveArea.RECORD) {
volumeValue = this.recordVolume.get_value();
this._record.setVolume(volumeValue);
log("VOLUME VIS" + setVisibleID);
if (setVisibleID == ActiveArea.PLAY) {
log("volumeValue.play " + volumeValue[0].play);
play.setVolume(volumeValue[0].play);
} else if (setVisibleID == ActiveArea.RECORD) {
this._record.setVolume(volumeValue[0].record);
}
},
getVolume: function() {
let volumeValue = this.playVolume.get_value();
return volumeValue;
},
listBoxAdd: function() {
selectable = true;
this.groupGrid = groupGrid;
volumeValue.push({ record: 0.5, play: 0.5 });
activeProfile = AudioProfile.comboBoxMap.OGG_VORBIS;
this.recordGrid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL,
height_request: 36,
......@@ -565,10 +576,10 @@ const MainView = new Lang.Class({
this.timeLabelString = this._formatTime(time);
if (this.setVisibleID == ActiveArea.RECORD) {
if (setVisibleID == ActiveArea.RECORD) {
this.recordTimeLabel.label = this.timeLabelString;
this.recordTimeLabel.get_style_context().add_class('dim-label');
} else if (this.setVisibleID == ActiveArea.PLAY) {
} else if (setVisibleID == ActiveArea.PLAY) {
this.playTimeLabel.label = this.timeLabelString;
}
},
......@@ -579,7 +590,6 @@ const RecordButton = new Lang.Class({
Extends: Gtk.Button,
_init: function(activeProfile) {
this._activeProfile = activeProfile;
this.parent();
this.set_label("Record");
this.connect("clicked", Lang.bind(this, this._onRecord));
......@@ -587,10 +597,13 @@ const RecordButton = new Lang.Class({
_onRecord: function() {
this.set_sensitive(false);
view.setVisibleID = ActiveArea.RECORD;
setVisibleID = ActiveArea.RECORD;
view.recordGrid.show_all();
audioProfile.assignProfile();
view._record.startRecording();
if (activeProfile == null)
activeProfile = 0;
audioProfile.assignProfile(activeProfile);
view._record.startRecording(activeProfile);
wave = new Waveform.WaveForm(view.recordGrid);
}
});
......@@ -607,7 +620,7 @@ const PlayPauseButton = new Lang.Class({
_onPlayPauseToggled: function(listRow, selFile) {
this.activeState = play.getPipeStates();
view.setVisibleID = ActiveArea.PLAY;
setVisibleID = ActiveArea.PLAY;
log(listRow);
let width = listRow.get_allocated_width();
if (this.activeState != PipelineStates.PLAYING) {
......@@ -664,18 +677,18 @@ const EncoderComboBox = new Lang.Class({
// encoding setting labels in combobox
_init: function() {
this.parent();
let combo = [_("Ogg Vorbis"), _("Ogg Opus"), _("FLAC"), _("MP3"), _("AAC")];
let combo = [_("Ogg Vorbis"), _("Opus"), _("FLAC"), _("MP3"), _("AAC")];
for (let i = 0; i < combo.length; i++)
this.append_text(combo[i]);
this.set_sensitive(true);
this.set_active(activeProfile);
this.connect("changed", Lang.bind(this, this._onComboBoxTextChanged));
},
_onComboBoxTextChanged: function() {
let activeProfile = this.get_active();
audioProfile.assignProfile(activeProfile);
activeProfile = this.get_active();
}
});
......
......@@ -86,7 +86,9 @@ const _TENTH_SEC = 100000000;
if (this.ret == Gst.StateChangeReturn.FAILURE) {
log("Unable to set the playbin to the playing state.\n");
this.onEndOfStream();
}
} else if (this.ret == Gst.StateChangeReturn.SUCCESS) {
MainWindow.view.setVolume();
}
},
pausePlaying: function() {
......@@ -135,8 +137,8 @@ const _TENTH_SEC = 100000000;
break;
case Gst.MessageType.ERROR:
log("Error :" + e.parse_error());
this._showErrorDialog(_("Error:" + e.parse_error())); //should I only show for specific error messages
log("Error :" + message.parse_error());
this._showErrorDialog(_("Error:" + message.parse_error()));
break;
case Gst.MessageType.DURATION:
......@@ -243,8 +245,7 @@ const _TENTH_SEC = 100000000;
},
setVolume: function(value) {
let level = this.play.convert_volume(GstAudio.StreamVolumeFormat.LINEAR, GstAudio.StreamVolumeFormat.CUBIC, value);
this.play.set_volume(GstAudio.StreamVolumeFormat.CUBIC, level);
this.play.set_volume(GstAudio.StreamVolumeFormat.CUBIC, value);
},
passSelected: function(selected) { //I think this is unnecessary?
......
......@@ -28,6 +28,10 @@ const C_ = imports.gettext.pgettext;
const MainWindow = imports.mainWindow;
const Main = imports.main;
let comboBoxText = null;
let recordVolume= null;
let playVolume = null;
const Preferences = new Lang.Class({
Name: 'Preferences',
......@@ -67,8 +71,7 @@ const Preferences = new Lang.Class({
use_markup: true });
grid.attach(formatLabel, 0, 0, 1, 1);
let comboBoxText = new MainWindow.EncoderComboBox({ halign: Gtk.Align.END });
comboBoxText.set_active(0);
comboBoxText = new MainWindow.EncoderComboBox({ halign: Gtk.Align.END });
grid.attach(comboBoxText, 2, 0, 1, 1);
let volumeLabel = new Gtk.Label({ label: '<b>' + _("Volume") + '</b>',
......@@ -76,38 +79,38 @@ const Preferences = new Lang.Class({
use_markup: true });
grid.attach(volumeLabel, 0, 1, 2, 1);
this.playVolume = new Gtk.Scale({ orientation: Gtk.Orientation.HORIZONTAL });
this.playRange = Gtk.Adjustment.new(0.75, 0, 1.0, 0.05, 0.0, 0.0);
this.playVolume.set_adjustment(this.playRange);
this.playVolume.set_sensitive(true);
this.playVolume.connect("value-changed", Lang.bind(this,
playVolume = new Gtk.Scale({ orientation: Gtk.Orientation.HORIZONTAL });
this.playRange = Gtk.Adjustment.new(MainWindow.volumeValue[0].play, 0, 1.0, 0.05, 0.0, 0.0);
playVolume.set_adjustment(this.playRange);
playVolume.set_sensitive(true);
playVolume.connect("value-changed", Lang.bind(this,
function() {
MainWindow.view.setVisibleID == MainWindow.ActiveArea.PLAY;
MainWindow.view.setVolume();
MainWindow.view.presetVolume(MainWindow.ActiveArea.PLAY, playVolume.get_value());
}));
grid.attach(this.playVolume, 2, 1, 2, 1);
grid.attach(playVolume, 2, 1, 2, 1);
let micVolLabel = new Gtk.Label({ label: '<b>' + _("Microphone") + '</b>',
halign: Gtk.Align.START,
use_markup: true });
grid.attach(micVolLabel, 0, 2, 2, 1);
this.recordVolume = new Gtk.Scale({ orientation: Gtk.Orientation.HORIZONTAL });
this.recordRange = Gtk.Adjustment.new(0.75, 0, 1.0, 0.05, 0.0, 0.0);
this.recordVolume.set_adjustment(this.recordRange);
this.recordVolume.set_sensitive(true);
this.recordVolume.connect("value-changed", Lang.bind(this,
recordVolume = new Gtk.Scale({ orientation: Gtk.Orientation.HORIZONTAL });
this.recordRange = Gtk.Adjustment.new(MainWindow.volumeValue[0].record, 0, 1.0, 0.05, 0.0, 0.0);
recordVolume.set_adjustment(this.recordRange);
recordVolume.set_sensitive(true);
recordVolume.connect("value-changed", Lang.bind(this,
function() {
MainWindow.view.setVisibleID == MainWindow.ActiveArea.RECORD;
MainWindow.view.setVolume();
MainWindow.view.presetVolume(MainWindow.ActiveArea.RECORD, recordVolume.get_value());
}));
grid.attach(this.recordVolume, 2, 2, 2, 1);
grid.attach(recordVolume, 2, 2, 2, 1);
this.widget.show_all();
},
onDoneClicked: function() {
this.widget.destroy();
}
},
});
......@@ -150,10 +150,12 @@ const Record = new Lang.Class({
return true;
},
startRecording: function(activeProfile) {
this._activeProfile = activeProfile;
startRecording: function(profile) {
this.profile = profile;
log("PROFILE" + this.profile);
this._audioProfile = MainWindow.audioProfile;
this._mediaProfile = this._audioProfile.mediaProfile();
log("Media Profile was set." + this._mediaProfile);
if (this._mediaProfile == -1) {
log("No Media Profile was set.");
......@@ -168,8 +170,10 @@ const Record = new Lang.Class({
if (ret == Gst.StateChangeReturn.FAILURE) {
log("Unable to set the pipeline to the recording state.\n"); //create return string?
this.onEndOfStream();
} else if (ret == Gst.StateChangeReturn.SUCCESS) {
MainWindow.view.setVolume();
}
if (!this.timeout) {
this.timeout = GLib.timeout_add(GLib.PRIORITY_DEFAULT, MainWindow._SEC_TIMEOUT, Lang.bind(this, this._updateTime));
}
......@@ -204,7 +208,7 @@ const Record = new Lang.Class({
case Gst.MessageType.ELEMENT:
log("elem");
if (GstPbutils.is_missing_plugin_message(this.localMsg)) { //buggy?
if (GstPbutils.is_missing_plugin_message(this.localMsg)) {
let detail = GstPbutils.missing_plugin_message_get_installer_detail(this.localMsg);
if (detail != null)
......@@ -219,26 +223,36 @@ const Record = new Lang.Class({
}
let s = message.get_structure();
if (s) {
if (s.has_name("level")) {
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");
log(dur);
let runTime = s.get_value("running-time");
log(runTime);
peakVal = s.get_value("peak");
log("peakVal" + peakVal);
if (peakVal) {
let val = peakVal.get_nth(0);
log("val" + val);
let value = Math.pow(val, 3);
this.peak = value * 0.001;
log("wave height" + this.peak);
if (s) {
if (s.has_name("level")) {
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");
log(dur);
let runTime = s.get_value("running-time");
log(runTime);
peakVal = s.get_value("peak");
log("peakVal" + peakVal);
if (peakVal) {
let val = peakVal.get_nth(0);
log("val" + val);
log("profile!" + this.profile);
let value = Math.pow(10, val/20);
log(value);
if (value <= 0)
this.peak = 0;
else if (value >= 1)
this.peak = 1;
else
this.peak = value;
log("wave height" + this.peak);
}
}
}
......@@ -251,16 +265,15 @@ const Record = new Lang.Class({
case Gst.MessageType.ERROR:
log("error");
let errorMessage = msg.parse_error();
let errorMessage = message.parse_error(); // add general error dialog for the app to pop up for all cases
log(errorMessage);
break;
}
},
setVolume: function(value) {
let level = this.srcElement.convert_volume(GstAudio.StreamVolumeFormat.CUBIC, GstAudio.StreamVolumeFormat.LINEAR, value);
log(level);
this.srcElement.set_volume(GstAudio.StreamVolumeFormat.LINEAR, level);
let level = value;
this.srcElement.set_volume(GstAudio.StreamVolumeFormat.CUBIC, level);
}
});
......
......@@ -35,8 +35,8 @@ const Mainloop = imports.mainloop;
const MainWindow = imports.mainWindow;
const peaks = [];
const INTERVAL = 100000000;
const peaks = [];
const pauseVal = 10;
const waveSamples = 40;
......@@ -51,6 +51,8 @@ const WaveForm = new Lang.Class({
_init: function(grid, file) {
this._grid = grid;
for (let i = 0; i < 40; i++)
peaks.push(-100);
if (file) {
this.waveType = WaveType.PLAY;
this.file = file;
......@@ -90,9 +92,8 @@ const WaveForm = new Lang.Class({
},
_launchPipeline: function() {
this.peaks = null;
this.pipeline =
Gst.parse_launch("uridecodebin name=decode uri=" + this._uri + " ! audioconvert ! audio/x-raw,channels=1 !level name=wavelevel interval=100000000 post-messages=true ! fakesink qos=false");
Gst.parse_launch("uridecodebin name=decode uri=" + this._uri + " ! audioconvert ! audio/x-raw,channels=1 !level name=level interval=100000000 post-messages=true ! fakesink qos=false");
this._level = this.pipeline.get_by_name("wavelevel");
let decode = this.pipeline.get_by_name("decode");
let bus = this.pipeline.get_bus();
......@@ -120,28 +121,29 @@ const WaveForm = new Lang.Class({
let s = message.get_structure();
if (s) {
if (s.has_name("level")) {
let p = null;
let peakVal = 0;
let peaknumber = 0;
let value = 0;
let st = s.get_value("timestamp");
let dur = s.get_value("duration");
let runTime = s.get_value("running-time");
log(runTime);
peakVal = s.get_value("peak");
let peakVal = s.get_value("peak");
if (peakVal) {
let val = peakVal.get_nth(0);
if (val >= 0) {
value = Math.pow(val, 1/3);
peaknumber = value * 0.1;
log("wave height" + value);
} else {
log("val" + val);
let value = Math.pow(10, val/20);
log(value);
if (value <= 0)
peaknumber = 0;
}
else if (value >= 1)
peaknumber = 1;
else
peaknumber = value;
peaks.push(peaknumber);
}
log("wave height" + peaknumber);
}
}
}
log("length of the peaks array" + peaks.length);
......@@ -173,65 +175,45 @@ const WaveForm = new Lang.Class({
},
fillSurface: function(drawing, cr) {
if (this.waveType == WaveType.PLAY) {
log("fill surface error" + this.waveType);
if (this.waveType == WaveType.PLAY) {
if (peaks.length != this.playTime) {
this.pipeline.set_state(Gst.State.PLAYING);
log("continue drawing " + peaks.length);
}
}
let start = 0;
let i = 0;
let base;
let w = this.drawing.get_allocated_width();
let xAxis = 0;
let end = this.tick + 39;
log(end);
let width = this.drawing.get_allocated_width();
log("w " + w);
let h = this.drawing.get_allocated_height();
let waveheight = this.drawing.get_allocated_height();
log("h" + h)
let length = this.nSamples;
log("length " + this.nSamples);
let waveheight = h;
let pixelsPerSample = w/waveSamples;
log("pixelsPerSample " + pixelsPerSample);
let pixelsPerSample = width/waveSamples;
log("pixelsPerSample " + pixelsPerSample);
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;
}
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);
cr.setLineWidth(1);
cr.setSourceRGBA(0.0, 185, 161, 255);
for(i; i < this.tick; i++) {
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)));
}
}
if (this.tick > waveSamples)
start += 1;
for(i = this.tick; i <= end; i++) {
// Keep moving until we get to a non-null array member
if (peaks[i] < 0 || (this.tick > 39 && xAxis == 0))
cr.moveTo((xAxis * pixelsPerSample), waveheight);
// Start drawing when we reach the first non-null array member
if (peaks[i] != null && peaks[i] >= 0)
cr.lineTo((xAxis * pixelsPerSample), (waveheight - (peaks[i] * waveheight)));
xAxis += 1;
}
cr.lineTo(w, h);
cr.lineTo(width, waveheight);
cr.closePath();
cr.strokePreserve();
cr.setSource(gradient);
......@@ -242,6 +224,7 @@ const WaveForm = new Lang.Class({
let lastTime;
if (this.waveType == WaveType.PLAY) {
lastTime = this.playTime;
log("lastTime time" + lastTime);
this.playTime = playTime;
log("check peaks" + peaks.length);
log("playTime time" + this.playTime);
......
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