From e1eba17e0f120c7194e6738e1ce0574c9735d308 Mon Sep 17 00:00:00 2001 From: Jakub Klimek Date: Tue, 22 Sep 2020 17:00:06 +0200 Subject: [PATCH 1/8] Made customized device --- impl/linux.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/impl/linux.js b/impl/linux.js index b6a5810..c407e06 100644 --- a/impl/linux.js +++ b/impl/linux.js @@ -35,22 +35,22 @@ function parseInfo (data) { return { volume: parseInt(result[1], 10), muted: (result[2] === 'off') } } -async function getInfo () { - return parseInfo(await amixer('get', await getDefaultDevice())) +async function getInfo (device) { + return parseInfo(await amixer('get', !!device ? device : await getDefaultDevice())) } -exports.getVolume = async function getVolume () { - return (await getInfo()).volume +exports.getVolume = async function getVolume (device) { + return (await getInfo(device)).volume } -exports.setVolume = async function setVolume (val) { - await amixer('set', await getDefaultDevice(), val + '%') +exports.setVolume = async function setVolume (val, device) { + await amixer('set', !!device ? device : await getDefaultDevice(), val + '%') } -exports.getMuted = async function getMuted () { - return (await getInfo()).muted +exports.getMuted = async function getMuted (device) { + return (await getInfo(device)).muted } -exports.setMuted = async function setMuted (val) { - await amixer('set', await getDefaultDevice(), val ? 'mute' : 'unmute') +exports.setMuted = async function setMuted (val, device) { + await amixer('set', !!device ? device : await getDefaultDevice(), val ? 'mute' : 'unmute') } From 16485b6fedca4a02981b14f10f382f6eede39491 Mon Sep 17 00:00:00 2001 From: Jakub Klimek Date: Tue, 22 Sep 2020 17:02:53 +0200 Subject: [PATCH 2/8] Update linux.js --- impl/linux.js | 1 + 1 file changed, 1 insertion(+) diff --git a/impl/linux.js b/impl/linux.js index c407e06..e684f1a 100644 --- a/impl/linux.js +++ b/impl/linux.js @@ -36,6 +36,7 @@ function parseInfo (data) { } async function getInfo (device) { + console.log('get', !!device ? device : await getDefaultDevice()) return parseInfo(await amixer('get', !!device ? device : await getDefaultDevice())) } From beee2b2aa01a174cac416bda933445f9b4487738 Mon Sep 17 00:00:00 2001 From: Jakub Klimek Date: Tue, 22 Sep 2020 17:16:23 +0200 Subject: [PATCH 3/8] Update linux.js --- impl/linux.js | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/impl/linux.js b/impl/linux.js index e684f1a..142e678 100644 --- a/impl/linux.js +++ b/impl/linux.js @@ -25,6 +25,16 @@ async function getDefaultDevice () { const reInfo = /[a-z][a-z ]*: Playback [0-9-]+ \[([0-9]+)%\] (?:[[0-9.-]+dB\] )?\[(on|off)\]/i +function buildArgs(cmd, device, card){ + var res = [cmd] + res.push(!!device ? device : await getDefaultDevice()) + if(card){ + res.push('-c') + res.push(card) + } + return res +} + function parseInfo (data) { const result = reInfo.exec(data) @@ -35,23 +45,26 @@ function parseInfo (data) { return { volume: parseInt(result[1], 10), muted: (result[2] === 'off') } } -async function getInfo (device) { - console.log('get', !!device ? device : await getDefaultDevice()) - return parseInfo(await amixer('get', !!device ? device : await getDefaultDevice())) +async function getInfo (device, card) { + return parseInfo(await amixer.apply(null, buildArgs('get', device, card)) } -exports.getVolume = async function getVolume (device) { - return (await getInfo(device)).volume +exports.getVolume = async function getVolume (device, card) { + return (await getInfo(device, card)).volume } -exports.setVolume = async function setVolume (val, device) { - await amixer('set', !!device ? device : await getDefaultDevice(), val + '%') +exports.setVolume = async function setVolume (val, device, card) { + var args = buildArgs('set',device, card) + args.push(val + '%') + await amixer.apply(null, args) } -exports.getMuted = async function getMuted (device) { - return (await getInfo(device)).muted +exports.getMuted = async function getMuted (device, card) { + return (await getInfo(device, card)).muted } -exports.setMuted = async function setMuted (val, device) { - await amixer('set', !!device ? device : await getDefaultDevice(), val ? 'mute' : 'unmute') +exports.setMuted = async function setMuted (val, device, card) { + var args = buildArgs('set',device, card) + args.push(val ? 'mute' : 'unmute') + await amixer.apply(null, args) } From 94e61f1c70ac0f49cc622a2f341d3f64d61f7e67 Mon Sep 17 00:00:00 2001 From: Jakub Klimek Date: Tue, 22 Sep 2020 17:18:17 +0200 Subject: [PATCH 4/8] Update linux.js --- impl/linux.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/impl/linux.js b/impl/linux.js index 142e678..78158a7 100644 --- a/impl/linux.js +++ b/impl/linux.js @@ -25,7 +25,7 @@ async function getDefaultDevice () { const reInfo = /[a-z][a-z ]*: Playback [0-9-]+ \[([0-9]+)%\] (?:[[0-9.-]+dB\] )?\[(on|off)\]/i -function buildArgs(cmd, device, card){ +async function buildArgs(cmd, device, card){ var res = [cmd] res.push(!!device ? device : await getDefaultDevice()) if(card){ @@ -46,7 +46,7 @@ function parseInfo (data) { } async function getInfo (device, card) { - return parseInfo(await amixer.apply(null, buildArgs('get', device, card)) + return parseInfo(await amixer.apply(null, buildArgs('get', device, card))) } exports.getVolume = async function getVolume (device, card) { From ee7587c4fdd04d6f8dc04b97f902a316eade3053 Mon Sep 17 00:00:00 2001 From: Jakub Klimek Date: Tue, 22 Sep 2020 17:48:00 +0200 Subject: [PATCH 5/8] Update linux.js --- impl/linux.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/impl/linux.js b/impl/linux.js index 78158a7..5d0d699 100644 --- a/impl/linux.js +++ b/impl/linux.js @@ -49,9 +49,10 @@ async function getInfo (device, card) { return parseInfo(await amixer.apply(null, buildArgs('get', device, card))) } -exports.getVolume = async function getVolume (device, card) { +async function getVolume(device, card) { return (await getInfo(device, card)).volume } +exports.getVolume = getVolume; exports.setVolume = async function setVolume (val, device, card) { var args = buildArgs('set',device, card) From 57469bed4de09ea87f13dfaaf65e1fd0b9e7ed7c Mon Sep 17 00:00:00 2001 From: Jakub Klimek Date: Tue, 22 Sep 2020 17:51:03 +0200 Subject: [PATCH 6/8] Update index.js --- index.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index c73127d..27cdf30 100644 --- a/index.js +++ b/index.js @@ -16,16 +16,16 @@ switch (os.type()) { } module.exports = { - setVolume (volume) { - return impl.setVolume(volume) + setVolume (volume, d, c) { + return impl.setVolume(volume, d, c) }, - getVolume () { - return impl.getVolume() + getVolume (d, c) { + return impl.getVolume(d, c) }, - setMuted (muted) { - return impl.setMuted(muted) + setMuted (muted, d, c) { + return impl.setMuted(muted, d, c) }, - getMuted () { - return impl.getMuted() + getMuted (d, c) { + return impl.getMuted(d, c) } } From 2d01b659c88bfa90b29840aaada290a011d155c1 Mon Sep 17 00:00:00 2001 From: Jakub Klimek Date: Tue, 22 Sep 2020 18:08:58 +0200 Subject: [PATCH 7/8] Update linux.js --- impl/linux.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/impl/linux.js b/impl/linux.js index 5d0d699..76a1a28 100644 --- a/impl/linux.js +++ b/impl/linux.js @@ -1,6 +1,7 @@ const execa = require('execa') async function amixer (...args) { + console.log(args) return (await execa('amixer', args)).stdout } @@ -46,13 +47,15 @@ function parseInfo (data) { } async function getInfo (device, card) { - return parseInfo(await amixer.apply(null, buildArgs('get', device, card))) + var a = buildArgs('get', device, card) + console.log(a) + console.log(await amixer.apply(null, a)) + return parseInfo(await amixer.apply(null, a)) } -async function getVolume(device, card) { +exports.getVolume = async function getVolume(device, card) { return (await getInfo(device, card)).volume } -exports.getVolume = getVolume; exports.setVolume = async function setVolume (val, device, card) { var args = buildArgs('set',device, card) From 001f3cb8da2277652b963f529278d0b31f2bac47 Mon Sep 17 00:00:00 2001 From: Jakub Klimek Date: Tue, 22 Sep 2020 18:14:36 +0200 Subject: [PATCH 8/8] Update linux.js --- impl/linux.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/impl/linux.js b/impl/linux.js index 76a1a28..532c955 100644 --- a/impl/linux.js +++ b/impl/linux.js @@ -1,7 +1,6 @@ const execa = require('execa') async function amixer (...args) { - console.log(args) return (await execa('amixer', args)).stdout } @@ -47,10 +46,7 @@ function parseInfo (data) { } async function getInfo (device, card) { - var a = buildArgs('get', device, card) - console.log(a) - console.log(await amixer.apply(null, a)) - return parseInfo(await amixer.apply(null, a)) + return parseInfo(await amixer.apply(null, await buildArgs('get', device, card))) } exports.getVolume = async function getVolume(device, card) { @@ -58,7 +54,7 @@ exports.getVolume = async function getVolume(device, card) { } exports.setVolume = async function setVolume (val, device, card) { - var args = buildArgs('set',device, card) + var args = await buildArgs('set',device, card) args.push(val + '%') await amixer.apply(null, args) } @@ -68,7 +64,7 @@ exports.getMuted = async function getMuted (device, card) { } exports.setMuted = async function setMuted (val, device, card) { - var args = buildArgs('set',device, card) + var args = await buildArgs('set',device, card) args.push(val ? 'mute' : 'unmute') await amixer.apply(null, args) }