Read and write correct sample rate
This commit is contained in:
parent
fa4084ae07
commit
58691da7f9
1 changed files with 29 additions and 4 deletions
33
extension.js
33
extension.js
|
@ -41,7 +41,7 @@ const Indicator = GObject.registerClass(
|
||||||
style_class: 'system-status-icon',
|
style_class: 'system-status-icon',
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let sampleRate = getCurrentSampleRate();
|
let sampleRate = getForcedSampleRate();
|
||||||
let currentSampleRate = new PopupMenu.PopupMenuItem(_("Sample Rate: " + sampleRate));
|
let currentSampleRate = new PopupMenu.PopupMenuItem(_("Sample Rate: " + sampleRate));
|
||||||
this.menu.addMenuItem(currentSampleRate);
|
this.menu.addMenuItem(currentSampleRate);
|
||||||
|
|
||||||
|
@ -51,8 +51,9 @@ const Indicator = GObject.registerClass(
|
||||||
let allowedRate = new PopupMenu.PopupMenuItem(_("Allowed Rates: " + allowedRates[i]));
|
let allowedRate = new PopupMenu.PopupMenuItem(_("Allowed Rates: " + allowedRates[i]));
|
||||||
allowedRate.connect('activate', () => {
|
allowedRate.connect('activate', () => {
|
||||||
console.log("set sample rate " + allowedRates[i]);
|
console.log("set sample rate " + allowedRates[i]);
|
||||||
|
|
||||||
setSampleRate(allowedRates[i]);
|
setSampleRate(allowedRates[i]);
|
||||||
currentSampleRate.label.text = "Sample Rate: " + getCurrentSampleRate();
|
currentSampleRate.label.text = "Sample Rate: " + getForcedSampleRate();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.menu.addMenuItem(allowedRate);
|
this.menu.addMenuItem(allowedRate);
|
||||||
|
@ -83,13 +84,37 @@ function init(meta) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function setSampleRate(sampleRate) {
|
function setSampleRate(sampleRate) {
|
||||||
spawnCommandLine("pw-metadata -n settings 0 clock.rate " + sampleRate);
|
spawnCommandLine("pw-metadata -n settings 0 clock.force-rate " + sampleRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCurrentSampleRate() {
|
function getForcedSampleRate() {
|
||||||
let res = spawnCommandLine("pw-metadata -n settings");
|
let res = spawnCommandLine("pw-metadata -n settings");
|
||||||
let lines = res.split(/\r?\n/);
|
let lines = res.split(/\r?\n/);
|
||||||
|
|
||||||
|
for (let i = 0; i < lines.length; i++) {
|
||||||
|
if (lines[i].includes('clock.force-rate')) {
|
||||||
|
console.log("found current force rate setting");
|
||||||
|
|
||||||
|
let phrases = lines[i].split(" ");
|
||||||
|
|
||||||
|
for (let j = 0; j < phrases.length; j++) {
|
||||||
|
if (phrases[j].includes("value")) {
|
||||||
|
let value = phrases[j].slice(7, -1);
|
||||||
|
|
||||||
|
console.log("with current value " + value);
|
||||||
|
|
||||||
|
if (value) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return getCurrentSampleRate(lines);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCurrentSampleRate(lines) {
|
||||||
for (let i = 0; i < lines.length; i++) {
|
for (let i = 0; i < lines.length; i++) {
|
||||||
if (lines[i].includes('clock.rate')) {
|
if (lines[i].includes('clock.rate')) {
|
||||||
let phrases = lines[i].split(" ");
|
let phrases = lines[i].split(" ");
|
||||||
|
|
Loading…
Reference in a new issue