diff --git a/assignment-client/src/audio/AudioMixer.cpp b/assignment-client/src/audio/AudioMixer.cpp index d32576956a..8caf4ddf09 100644 --- a/assignment-client/src/audio/AudioMixer.cpp +++ b/assignment-client/src/audio/AudioMixer.cpp @@ -194,20 +194,12 @@ int AudioMixer::addStreamToMixForListeningNodeWithStream(AudioMixerClientData* l attenuationCoefficient *= offAxisCoefficient; } - - bool wantBreak = false; + float attenuationPerDoublingInDistance = _attenuationPerDoublingInDistance; - foreach (const QString& source, _attenuationCoefficients.keys()) { - if (_audioZones[source].contains(streamToAdd->getPosition())) { - foreach (const QString& listener, _attenuationCoefficients[source].keys()) { - if (_audioZones[listener].contains(listeningNodeStream->getPosition())) { - attenuationPerDoublingInDistance = _attenuationCoefficients[source][listener]; - wantBreak = true; - break; - } - } - } - if (wantBreak) { + for (int i = 0; i < _zonesSettings.length(); ++i) { + if (_audioZones[_zonesSettings[i].source].contains(streamToAdd->getPosition()) && + _audioZones[_zonesSettings[i].listener].contains(listeningNodeStream->getPosition())) { + attenuationPerDoublingInDistance = _zonesSettings[i].coefficient; break; } } @@ -1025,21 +1017,18 @@ void AudioMixer::parseSettingsObject(const QJsonObject &settingsObject) { coefficientObject.contains(LISTENER) && coefficientObject.contains(COEFFICIENT)) { - bool ok; - QString source = coefficientObject.value(SOURCE).toString(); - QString listener = coefficientObject.value(LISTENER).toString(); - float coefficient = coefficientObject.value(COEFFICIENT).toString().toFloat(&ok); + ZonesSettings settings; - if (ok && coefficient >= 0.0f && coefficient <= 1.0f && - _audioZones.contains(source) && _audioZones.contains(listener)) { + bool ok; + settings.source = coefficientObject.value(SOURCE).toString(); + settings.listener = coefficientObject.value(LISTENER).toString(); + settings.coefficient = coefficientObject.value(COEFFICIENT).toString().toFloat(&ok); + + if (ok && settings.coefficient >= 0.0f && settings.coefficient <= 1.0f && + _audioZones.contains(settings.source) && _audioZones.contains(settings.listener)) { - if (!_attenuationCoefficients.contains(source)) { - _attenuationCoefficients.insert(source, QHash()); - } - if (!_attenuationCoefficients[source].contains(listener)) { - _attenuationCoefficients[source].insert(listener, coefficient); - qDebug() << "Added Coefficient:" << source << listener << coefficient; - } + _zonesSettings.push_back(settings); + qDebug() << "Added Coefficient:" << settings.source << settings.listener << settings.coefficient; } } } diff --git a/assignment-client/src/audio/AudioMixer.h b/assignment-client/src/audio/AudioMixer.h index 7f07c846a4..3cfa5443a8 100644 --- a/assignment-client/src/audio/AudioMixer.h +++ b/assignment-client/src/audio/AudioMixer.h @@ -74,8 +74,14 @@ private: int _numStatFrames; int _sumListeners; int _sumMixes; + QHash _audioZones; - QHash > _attenuationCoefficients; + struct ZonesSettings { + QString source; + QString listener; + float coefficient; + }; + QVector _zonesSettings; static InboundAudioStream::Settings _streamSettings; diff --git a/domain-server/resources/describe-settings.json b/domain-server/resources/describe-settings.json index 3a1fbd4526..b8bc783aa1 100644 --- a/domain-server/resources/describe-settings.json +++ b/domain-server/resources/describe-settings.json @@ -132,7 +132,8 @@ "type": "table", "label": "Attenuation Coefficients", "help": "In this table you can set custom attenuation coefficients between audio zones", - "numbered": false, + "numbered": true, + "can_order": true, "columns": [ { "name": "source", @@ -158,7 +159,7 @@ }, { "name": "audio_buffer", - "label": "Audio Buffer", + "label": "Audio Buffers", "assignment-types": [0], "settings": [ { diff --git a/domain-server/resources/web/css/style.css b/domain-server/resources/web/css/style.css index ad889274d4..1aab383a7d 100644 --- a/domain-server/resources/web/css/style.css +++ b/domain-server/resources/web/css/style.css @@ -79,12 +79,19 @@ td.buttons { width: 14px; } -td.buttons .glyphicon { - display: block; +td .glyphicon { text-align: center; font-size: 12px; } +td.add-del-buttons .glyphicon { + display: block; +} + +td.reorder-buttons .glyphicon { + display: inherit; +} + tr.new-row { color: #3c763d; background-color: #dff0d8; diff --git a/domain-server/resources/web/js/settings.js b/domain-server/resources/web/js/settings.js index 3b7e449d4c..c2223a8f55 100644 --- a/domain-server/resources/web/js/settings.js +++ b/domain-server/resources/web/js/settings.js @@ -8,7 +8,15 @@ var Settings = { ADD_ROW_SPAN_CLASSES: 'glyphicon glyphicon-plus add-row', DEL_ROW_BUTTON_CLASS: 'del-row', DEL_ROW_SPAN_CLASSES: 'glyphicon glyphicon-remove del-row', + MOVE_UP_BUTTON_CLASS: 'move-up', + MOVE_UP_SPAN_CLASSES: 'glyphicon glyphicon-chevron-up move-up', + MOVE_DOWN_BUTTON_CLASS: 'move-down', + MOVE_DOWN_SPAN_CLASSES: 'glyphicon glyphicon-chevron-down move-down', TABLE_BUTTONS_CLASS: 'buttons', + ADD_DEL_BUTTONS_CLASS: 'add-del-buttons', + ADD_DEL_BUTTONS_CLASSES: 'buttons add-del-buttons', + REORDER_BUTTONS_CLASS: 'reorder-buttons', + REORDER_BUTTONS_CLASSES: 'buttons reorder-buttons', NEW_ROW_CLASS: 'new-row' }; @@ -110,6 +118,14 @@ $(document).ready(function(){ $('#settings-form').on('click', '.' + Settings.DEL_ROW_BUTTON_CLASS, function(){ deleteTableRow(this); }) + + $('#settings-form').on('click', '.' + Settings.MOVE_UP_BUTTON_CLASS, function(){ + moveTableRow(this, true); + }) + + $('#settings-form').on('click', '.' + Settings.MOVE_DOWN_BUTTON_CLASS, function(){ + moveTableRow(this, false); + }) $('#settings-form').on('keypress', 'table input', function(e){ if (e.keyCode == 13) { @@ -120,7 +136,7 @@ $(document).ready(function(){ if (sibling.hasClass(Settings.DATA_COL_CLASS)) { // set focus to next input sibling.find('input').focus() - } else if (sibling.hasClass(Settings.TABLE_BUTTONS_CLASS)) { + } else if (sibling.hasClass(Settings.ADD_DEL_BUTTONS_CLASS)) { sibling.find('.' + Settings.ADD_ROW_BUTTON_CLASS).click() // set focus to the first input in the new row @@ -239,6 +255,10 @@ $('body').on('click', '.save-button', function(e){ function makeTable(setting, setting_name, setting_value) { var isArray = !_.has(setting, 'key') + if (!isArray && setting.can_order) { + setting.can_order = false; + } + var html = (setting.label) ? "" : "" html += "" + setting.help + "" html += "" + col.label + "" // Data }) - html += "" + if (setting.can_order) { + html += ""; + } + html += "" // populate rows in the table from existing values var row_num = 1 @@ -293,7 +317,13 @@ function makeTable(setting, setting_name, setting_value) { html += "" }) - html += "" + if (setting.can_order) { + html += "" + } + html += "" html += "" row_num++ @@ -324,8 +354,12 @@ function makeTableInputs(setting) { \ " }) - - html += "" + + if (setting.can_order) { + html += "" + } + html += "" html += "" return html @@ -418,7 +452,10 @@ function addTableRow(add_glyphicon) { } else { $(element).html(1) } - } else if ($(element).hasClass("buttons")) { + } else if ($(element).hasClass(Settings.REORDER_BUTTONS_CLASS)) { + $(element).html("") + } else if ($(element).hasClass(Settings.ADD_DEL_BUTTONS_CLASS)) { // Change buttons var span = $(element).children("span") span.removeClass(Settings.ADD_ROW_SPAN_CLASSES) @@ -499,7 +536,32 @@ function deleteTableRow(delete_glyphicon) { // we need to fire a change event on one of the remaining inputs so that the sidebar badge is updated badgeSidebarForDifferences($(table)) -} +} + +function moveTableRow(move_glyphicon, move_up) { + var row = $(move_glyphicon).closest('tr') + + var table = $(row).closest('table') + var isArray = table.data('setting-type') === 'array' + if (!isArray) { + return; + } + + if (move_up) { + var prev_row = row.prev() + if (prev_row.hasClass(Settings.DATA_ROW_CLASS)) { + prev_row.before(row) + } + } else { + var next_row = row.next() + if (next_row.hasClass(Settings.DATA_ROW_CLASS)) { + next_row.after(row) + } + } + + // we need to fire a change event on one of the remaining inputs so that the sidebar badge is updated + badgeSidebarForDifferences($(table)) +} function updateDataChangedForSiblingRows(row, forceTrue) { // anytime a new row is added to an array we need to set data-changed for all sibling row inputs to true diff --git a/domain-server/resources/web/settings/index.shtml b/domain-server/resources/web/settings/index.shtml index 9bc8d4bf8f..598f137285 100644 --- a/domain-server/resources/web/settings/index.shtml +++ b/domain-server/resources/web/settings/index.shtml @@ -22,7 +22,7 @@ - + @@ -32,25 +32,32 @@ - +