Skip to content

Commit

Permalink
hopefully fixed the changes suggested by robin beckett (subwolf@161af38
Browse files Browse the repository at this point in the history
…), but without needing c++11 (asked around in irc, "don't use void* userdata, ever!)
  • Loading branch information
kritzikratzi committed Nov 2, 2015
1 parent 7752c4a commit 38e8ecb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Oscilloscope.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@
E4B69B4C0A3A1720003C02F2 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0460;
LastUpgradeCheck = 0620;
};
buildConfigurationList = E4B69B4D0A3A1720003C02F2 /* Build configuration list for PBXProject "Oscilloscope" */;
compatibilityVersion = "Xcode 3.2";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0460"
LastUpgradeVersion = "0620"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -48,7 +48,8 @@
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<BuildableProductRunnable>
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E4B69B5A0A3A1756003C02F2"
Expand All @@ -66,7 +67,8 @@
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
debugDocumentVersioning = "YES">
<BuildableProductRunnable>
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E4B69B5A0A3A1756003C02F2"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0460"
LastUpgradeVersion = "0620"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
18 changes: 9 additions & 9 deletions src/ui/ConfigView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ ConfigView::ConfigView( float x_, float y_, float width_, float height_)
string name = string(info.name);
if( info.outputChannels > 0 ){
mui::ToggleButton * button = new mui::ToggleButton( name, x, y, w, h );
button->userData = (void*)(it-infos.begin());
deviceIds[button] = static_cast<int>(it-infos.begin());
ofAddListener( button->onPress, this, &ConfigView::buttonPressed );
button->fg = ofColor( 255 );
button->label->horizontalAlign = mui::Left;
Expand Down Expand Up @@ -122,7 +122,7 @@ void ConfigView::fromGlobals(){
bufferSizeSelect->selected = ofToString( globals.bufferSize );
numbuffersSelect->selected = ofToString( globals.numBuffers );

if( globals.deviceId < soundcardButtons.size() ){
if( (size_t)globals.deviceId < soundcardButtons.size() ){
selectSoundCard( globals.deviceId );
}
else{
Expand Down Expand Up @@ -165,18 +165,18 @@ void ConfigView::buttonPressed( const void * sender, ofTouchEventArgs & args ){
}
else{
mui::ToggleButton * btn = (mui::ToggleButton*)sender;
selectSoundCard((int)btn->userData);
selectSoundCard(deviceIds[btn]);
}
}

void ConfigView::selectSoundCard( int deviceId ){
if( deviceId < 0 && soundcardButtons.size() > 0 ){
deviceId = (int)soundcardButtons.front()->userData;
if( deviceId < 0 && !soundcardButtons.empty() ){
deviceId = deviceIds[soundcardButtons.front()];
}

for( int i = 0; i < soundcardButtons.size(); i++ ){
mui::ToggleButton * btn = soundcardButtons[i];
if( (int)btn->userData == deviceId ){
for( vector<mui::ToggleButton*>::iterator it = soundcardButtons.begin(); it != soundcardButtons.end(); ++it ){
mui::ToggleButton * btn = *it;
if( deviceIds[btn] == deviceId ){
selectedSoundCard = deviceId;
btn->selected = true;
}
Expand All @@ -193,7 +193,7 @@ void ConfigView::autoDetect(){
int bufferSize = 512;
int numBuffers = 4;
getDefaultRtOutputParams(deviceId, sampleRate, bufferSize, numBuffers);
if( deviceId < soundcardButtons.size() ) selectSoundCard(deviceId);
if( (size_t)deviceId < soundcardButtons.size() ) selectSoundCard(deviceId);
sampleRatesSelect->selected = ofToString(sampleRate);
sampleRatesSelect->commit();
bufferSizeSelect->selected = ofToString(bufferSize);
Expand Down
2 changes: 1 addition & 1 deletion src/ui/ConfigView.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "MUI.h"


class ConfigView : public mui::Container{
public:
ConfigView( float x_ = 0, float y_ = 0, float width_ = ofGetWidth(), float height_ = ofGetHeight() );
Expand Down Expand Up @@ -36,4 +35,5 @@ class ConfigView : public mui::Container{
void pushLabel( string text, float &x, float &y, float &w, float &h );
int selectedSoundCard;
vector<mui::ToggleButton*> soundcardButtons;
map<mui::ToggleButton*, int> deviceIds;
};

0 comments on commit 38e8ecb

Please sign in to comment.