Skip to content

Commit

Permalink
Fixed bug where devices was set with old format
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasArvidsson committed Mar 15, 2019
1 parent 751aa32 commit c6e60d4
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 78 deletions.
75 changes: 0 additions & 75 deletions Config.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
#include "Config.h"
#define NOMINMAX
#include <iostream> //cin
#include "JsonParser.h"
#include "Convert.h"
#include "WinDSPLog.h"
#include "AudioDevice.h"
#include "Input.h"
#include "Output.h"
#include "Visibility.h"
#include "FilterGain.h"
#include "Channel.h"

Config::Config(const std::string &path) {
_configFile = path;
Expand Down Expand Up @@ -87,74 +80,6 @@ const double Config::getFiltersLevelSum(const std::vector<Filter*> &filters, dou
return startLevel;
}

void Config::setDevices() {
Visibility::show(true);
const std::vector<std::string> wasapiDevices = AudioDevice::getDeviceNames();

size_t selectedIndex;
bool isOk;
do {
LOG_INFO("Available capture devices:\n");
for (size_t i = 0; i < wasapiDevices.size(); ++i) {
LOG_INFO("%zu: %s\n", i + 1, wasapiDevices[i].c_str());
}
//Make selection
selectedIndex = getSelection(1, wasapiDevices.size());
_captureDeviceName = wasapiDevices[selectedIndex - 1];

LOG_INFO("\nAvailable render devices:\n");
size_t index = 1;
for (size_t i = 0; i < wasapiDevices.size(); ++i, ++index) {
//Cant reuse capture device.
if (index != selectedIndex) {
LOG_INFO("%zu: %s\n", index, wasapiDevices[i].c_str());
}
}
//Make selection
selectedIndex = getSelection(1, wasapiDevices.size(), selectedIndex);

//Query if selection is ok.
LOG_INFO("\nSelected devices:\n");
LOG_INFO("Capture: %s\n", _captureDeviceName.c_str());
_renderDeviceName = wasapiDevices[selectedIndex - 1];
LOG_INFO("Render: %s\n", _renderDeviceName.c_str());
LOG_INFO("\nPress 1 to continue or 0 to re-select\n");
isOk = getSelection(0, 1) == 1;
LOG_NL();
} while (!isOk);

//Update json

if (!_pJsonNode->path("devices")->isObject()) {
_pJsonNode->put("devices", new JsonNode(JsonNodeType::OBJECT));
}
JsonNode *pDevicesNode = _pJsonNode->get("devices");

if (!_pJsonNode->path("capture")->isObject()) {
pDevicesNode->put("capture", new JsonNode(JsonNodeType::OBJECT));
}
JsonNode *pCaptureNode = pDevicesNode->get("capture");

if (!_pJsonNode->path("render")->isObject()) {
pDevicesNode->put("render", new JsonNode(JsonNodeType::OBJECT));
}
JsonNode *pRenderNode = pDevicesNode->get("render");

pCaptureNode->put("name", _captureDeviceName);
pRenderNode->put("name", _renderDeviceName);
save();
}

const size_t Config::getSelection(const size_t start, const size_t end, const size_t blacklist) const {
char buf[10];
int value;
do {
std::cin.getline(buf, 10);
value = atoi(buf);
} while (value < start || value > end || value == blacklist);
return value;
}

void Config::load() {
_pJsonNode = JsonParser::fromFile(_configFile);
_lastModified = _configFile.getLastModifiedTime();
Expand Down
2 changes: 1 addition & 1 deletion Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class Config {
void load();
void save();
const double getFiltersLevelSum(const std::vector<Filter*> &filters, double startLevel = 1.0) const;
void setDevices();
const size_t getSelection(const size_t start, const size_t end, const size_t blacklist = -1) const;
void printConfig() const;
void printRouteConfig(const Channel channel, const std::vector<Filter*> &filters, const std::vector<Filter*> &postFilters, const bool hasConditions = false) const;
Expand All @@ -73,6 +72,7 @@ class Config {
/* ********* ConfigParser.cpp ********* */

void parseDevices();
void setDevices();
void parseMisc();
void parseRouting();
void parseOutputs();
Expand Down
66 changes: 65 additions & 1 deletion ConfigParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@
#include "Channel.h"
#include "Convert.h"
#include "FilterGain.h"
#include "Visibility.h"
#include "AudioDevice.h"

#define NOMINMAX
#include <iostream> //cin

void Config::parseDevices() {
const JsonNode *pDevicesNode = _pJsonNode->path("devices");
std::string path;
const JsonNode *pDevicesNode = tryGetObjectNode(_pJsonNode, "devices", path);
//Devices not set in config. Query user
if (!pDevicesNode->has("capture") || !pDevicesNode->has("render")) {
setDevices();
Expand Down Expand Up @@ -174,3 +180,61 @@ void Config::validateLevels(const std::string &path) const {
}
}

void Config::setDevices() {
Visibility::show(true);
const std::vector<std::string> wasapiDevices = AudioDevice::getDeviceNames();

size_t selectedIndex;
bool isOk;
do {
LOG_INFO("Available capture devices:\n");
for (size_t i = 0; i < wasapiDevices.size(); ++i) {
LOG_INFO("%zu: %s\n", i + 1, wasapiDevices[i].c_str());
}
//Make selection
selectedIndex = getSelection(1, wasapiDevices.size());
_captureDeviceName = wasapiDevices[selectedIndex - 1];

LOG_INFO("\nAvailable render devices:\n");
size_t index = 1;
for (size_t i = 0; i < wasapiDevices.size(); ++i, ++index) {
//Cant reuse capture device.
if (index != selectedIndex) {
LOG_INFO("%zu: %s\n", index, wasapiDevices[i].c_str());
}
}
//Make selection
selectedIndex = getSelection(1, wasapiDevices.size(), selectedIndex);

//Query if selection is ok.
LOG_INFO("\nSelected devices:\n");
LOG_INFO("Capture: %s\n", _captureDeviceName.c_str());
_renderDeviceName = wasapiDevices[selectedIndex - 1];
LOG_INFO("Render: %s\n", _renderDeviceName.c_str());
LOG_INFO("\nPress 1 to continue or 0 to re-select\n");
isOk = getSelection(0, 1) == 1;
LOG_NL();
} while (!isOk);

//Update json

if (!_pJsonNode->path("devices")->isObject()) {
_pJsonNode->put("devices", new JsonNode(JsonNodeType::OBJECT));
}
JsonNode *pDevicesNode = _pJsonNode->get("devices");

pDevicesNode->put("capture", _captureDeviceName);
pDevicesNode->put("render", _renderDeviceName);

save();
}

const size_t Config::getSelection(const size_t start, const size_t end, const size_t blacklist) const {
char buf[10];
int value;
do {
std::cin.getline(buf, 10);
value = atoi(buf);
} while (value < start || value > end || value == blacklist);
return value;
}
2 changes: 1 addition & 1 deletion Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "TrayIcon.h"
#include "Str.h"

#define VERSION "0.19.1b"
#define VERSION "0.19.2b"

#ifdef DEBUG
#include "MemoryManager.h"
Expand Down
Binary file modified release/WinDSP.exe
Binary file not shown.

0 comments on commit c6e60d4

Please # to comment.