Changeset 2420:6a4d707ebb74 in roaraudio


Ignore:
Timestamp:
08/18/09 04:56:49 (15 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

much better way to handle defaults

Location:
roarclients
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • roarclients/roarcat.c

    r2407 r2420  
    4848 
    4949int main (int argc, char * argv[]) { 
    50  int    rate     = ROAR_RATE_DEFAULT; 
    51  int    bits     = ROAR_BITS_DEFAULT; 
    52  int    channels = ROAR_CHANNELS_DEFAULT; 
    53  int    codec    = ROAR_CODEC_DEFAULT; 
     50 int    rate     = -1; 
     51 int    bits     = -1; 
     52 int    channels = -1; 
     53 int    codec    = -1; 
    5454 int    dir      = ROAR_DIR_PLAY; 
    5555 int    rel_id   = -1; 
     
    9797  } else if ( !strcmp(k, "--midi") ) { 
    9898   dir      = ROAR_DIR_MIDI_IN; 
    99    bits     = ROAR_MIDI_BITS; 
    100    channels = ROAR_MIDI_CHANNELS_DEFAULT; 
    101    if ( codec == ROAR_CODEC_DEFAULT ) 
    102     codec = ROAR_CODEC_MIDI; 
    10399  } else if ( !strcmp(k, "--light") ) { 
    104100   dir   = ROAR_DIR_LIGHT_IN; 
    105    if ( codec == ROAR_CODEC_DEFAULT ) 
    106     codec = ROAR_CODEC_DMX512; 
    107101  } else if ( !strcmp(k, "--raw") ) { 
    108102   dir   = ROAR_DIR_RAW_IN; 
     
    125119   return 1; 
    126120  } 
     121 } 
     122 
     123 switch (dir) { 
     124  case ROAR_DIR_PLAY: 
     125    if ( rate     == -1 ) rate     = ROAR_RATE_DEFAULT; 
     126    if ( bits     == -1 ) bits     = ROAR_BITS_DEFAULT; 
     127    if ( channels == -1 ) channels = ROAR_CHANNELS_DEFAULT; 
     128    if ( codec    == -1 ) codec    = ROAR_CODEC_DEFAULT; 
     129   break; 
     130  case ROAR_DIR_MIDI_IN: 
     131    if ( rate     == -1 ) rate     = 0; 
     132    if ( bits     == -1 ) bits     = ROAR_MIDI_BITS; 
     133    if ( channels == -1 ) channels = ROAR_MIDI_CHANNELS_DEFAULT; 
     134    if ( codec    == -1 ) codec    = ROAR_CODEC_MIDI; 
     135   break; 
     136  case ROAR_DIR_LIGHT_IN: 
     137    if ( rate     == -1 ) rate     = 0; 
     138    if ( bits     == -1 ) bits     = ROAR_LIGHT_BITS; 
     139    if ( channels == -1 ) channels = 0; 
     140    if ( codec    == -1 ) codec    = ROAR_CODEC_DMX512; 
     141   break; 
     142  case ROAR_DIR_RAW_IN: 
     143  default: 
     144    if ( rate     == -1 ) rate     = 0; 
     145    if ( bits     == -1 ) bits     = 0; 
     146    if ( channels == -1 ) channels = 0; 
     147    if ( codec    == -1 ) codec    = ROAR_CODEC_DEFAULT; 
     148   break; 
    127149 } 
    128150 
  • roarclients/roarmon.c

    r2407 r2420  
    4949 
    5050int main (int argc, char * argv[]) { 
    51  int    rate     = ROAR_RATE_DEFAULT; 
    52  int    bits     = ROAR_BITS_DEFAULT; 
    53  int    channels = ROAR_CHANNELS_DEFAULT; 
    54  int    codec    = ROAR_CODEC_DEFAULT; 
     51 int    rate     = -1; 
     52 int    bits     = -1; 
     53 int    channels = -1; 
     54 int    codec    = -1; 
    5555 int    dir      = ROAR_DIR_MONITOR; 
    5656 int    rel_id   = -1; 
     
    9797  } else if ( !strcmp(k, "--midi") ) { 
    9898   dir      = ROAR_DIR_MIDI_OUT; 
    99    bits     = ROAR_MIDI_BITS; 
    100    channels = ROAR_MIDI_CHANNELS_DEFAULT; 
    101    if ( codec == ROAR_CODEC_DEFAULT ) 
    102     codec = ROAR_CODEC_MIDI; 
    10399  } else if ( !strcmp(k, "--light") ) { 
    104100   dir   = ROAR_DIR_LIGHT_OUT; 
    105    if ( codec == ROAR_CODEC_DEFAULT ) 
    106     codec = ROAR_CODEC_DMX512; 
    107101  } else if ( !strcmp(k, "--raw") ) { 
    108102   dir   = ROAR_DIR_RAW_OUT; 
     
    128122 } 
    129123 
     124 switch (dir) { 
     125  case ROAR_DIR_MONITOR: 
     126    if ( rate     == -1 ) rate     = ROAR_RATE_DEFAULT; 
     127    if ( bits     == -1 ) bits     = ROAR_BITS_DEFAULT; 
     128    if ( channels == -1 ) channels = ROAR_CHANNELS_DEFAULT; 
     129    if ( codec    == -1 ) codec    = ROAR_CODEC_DEFAULT; 
     130   break; 
     131  case ROAR_DIR_MIDI_OUT: 
     132    if ( rate     == -1 ) rate     = 0; 
     133    if ( bits     == -1 ) bits     = ROAR_MIDI_BITS; 
     134    if ( channels == -1 ) channels = ROAR_MIDI_CHANNELS_DEFAULT; 
     135    if ( codec    == -1 ) codec    = ROAR_CODEC_MIDI; 
     136   break; 
     137  case ROAR_DIR_LIGHT_OUT: 
     138    if ( rate     == -1 ) rate     = 0; 
     139    if ( bits     == -1 ) bits     = ROAR_LIGHT_BITS; 
     140    if ( channels == -1 ) channels = 0; 
     141    if ( codec    == -1 ) codec    = ROAR_CODEC_DMX512; 
     142   break; 
     143  case ROAR_DIR_RAW_OUT: 
     144  case ROAR_DIR_THRU: 
     145  default: 
     146    if ( rate     == -1 ) rate     = 0; 
     147    if ( bits     == -1 ) bits     = 0; 
     148    if ( channels == -1 ) channels = 0; 
     149    if ( codec    == -1 ) codec    = ROAR_CODEC_DEFAULT; 
     150   break; 
     151 } 
     152 
    130153 if ( roar_simple_connect(&con, server, "roarmon") == -1 ) { 
    131154  fprintf(stderr, "Error: can not connect to server\n"); 
Note: See TracChangeset for help on using the changeset viewer.