jishi / node-sonos-http-api

An HTTP API bridge for Sonos easing automation. Hostable on any node.js capable device, like a raspberry pi or similar.
http://jishi.github.io/node-sonos-http-api/
MIT License
1.85k stars 462 forks source link

add balance adjustment for sonos amp #454

Open Kamol81 opened 7 years ago

Kamol81 commented 7 years ago

Hi Is it possible to add settings for using the balance adjustment . One of my sonos is connected be wire to only one celling speaker in bathroom and I'd like to make "another zone" somewhere else but it would be excellent to choose them separately.

jishi commented 7 years ago

Nothing that I had planned, but I'll keep it around for consideration. Although, since you can't enforce a mono feed to the two speakers, I would advice against this setup to be honest :) A lot of tracks have clear audible differences between the channels, and it will sound odd, at best.

Lockzi commented 7 years ago

I am looking at this due to that I am using my Connect:AMP as a two zone setup feeding left and right to different areas of my outdoor speakers.

It's in theory pretty simple to do as the only thing that has to be done is use the same volume function, but adding in channel LF/RF instead of Master like it is now hardcoded to.

@jishi What would the best way to do this in a way you're willing to accept a pull request? And without having to re-write all the other functions.

Most of the logic resides in sonos-discovery/lib/models/Player.js and sonos-discovery/lib/helpers/soap.js for the UPNP templates

I am considering adding a default variable called channel that's defaulted to "Master"

Player.prototype.setVolume = function setVolume(level, channel) {

    if (data.volume) {
      let master = data.volume.find(x => x.channel === 'Master');
      const previousVolume = state.volume;
      state.volume = parseInt(master.val);

      _this.emit('volume-change', {
        previousVolume,
        newVolume: state.volume,
        roomName: _this.roomName
      });

      _this.system.emit('volume-change', {
        uuid: _this.uuid,
        previousVolume,
        newVolume: state.volume,
        roomName: _this.roomName
      });

      _this.coordinator.recalculateGroupVolume();
    }
jishi commented 7 years ago

@Lockzi We need to figure out if you only need to adjust LF/RF when setting balance (meaning, subsequent Master adjustments would obey the previous balance). This must surely be how it handles it.

Then it makes more sense to have some sort of balance() function that hides the fact that Sonos internally uses different Left/Right volume for balance.

Lockzi commented 7 years ago

@jishi

I've found this: https://github.com/chregu/fhem-sonos/blob/b6a97be8015b70644d71d74bf8224dcb20833a75/FHEM/00_SONOS.pm#L1207

What do you think about this section?

jishi commented 7 years ago

Seems weird that one channel would ever be >100... but having some sort of balance() that takes -100 to 100 or 0-100 or -50 to 50 or something would make sense.

Lockzi commented 7 years ago

The reason is simply because of his slider function which looks like this: https://github.com/chregu/fhem-sonos/blob/master/FHEM/00_SONOS.pm#L932

Lockzi commented 7 years ago

FYI

I have a working solution based on:

Balance:

0<----------50----->100
LF100      LF100        LF0
LR0          RF100        RF100

http://localhost:5005/{roomName}/balance/50 sets LF = 100 RF = 100

http://localhost:5005/{roomName}/balance/75 sets LF = 50 RF = 100

http://localhost:5005/{roomName}/balance/33 sets LF = 100 RF = 66

Will push both sonos-discovery as well as http-api tomorrow with your permission Jishi

jishi commented 7 years ago

Feel free to send PRs!

Lockzi commented 7 years ago

PR in place :) 👍

Lockzi commented 7 years ago

It needs update to both HTTP API as well as Discovery

Kamol81 commented 7 years ago

Is it working? How to check it out?

Kamol81 commented 6 years ago

Please help - How to turn it on?

gregkinney commented 6 years ago

Did this ever get implemented?

Kamol81 commented 6 years ago

It works only in FHEM