home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / SourceCode / MiscKit1.2.6 / Palettes / MiscSoundPalette / MiscSoundUtil.subproj / MiscVolumeLight.m < prev    next >
Encoding:
Text File  |  1994-05-27  |  2.4 KB  |  100 lines

  1. #import "MiscVolumeLight.h"
  2. #import <stdio.h>
  3.  
  4. @implementation MiscVolumeLight
  5.  
  6. - drawSelf:(const NXRect*) rects:(int) rectCount
  7.     {
  8.     int just_erase=0;
  9.     float left,right;
  10.     NXRect backgroundRect=bounds;
  11.     
  12.     //printf ("Displaying\n");
  13.     
  14.     if ([delegate respondsTo:@selector(meterWillUpdate:)])
  15.         [delegate meterWillUpdate:self];
  16.  
  17. //    if (![window isVisible]) return self;        // no window to draw in.
  18.     
  19.     //printf ("Window Visible\n");
  20.     
  21.     //if (![window isVisible]) return NULL;        // no window to draw in.
  22.     // the above has been turned off because when loading Resound,
  23.     // the sound meter wouldn't display until a sound was being played
  24.     // or recorded!
  25.     
  26.     
  27.     // first to check to see if the sound lock is current
  28.     ////printf ("Meter\n");
  29.     if (sound!=NULL)
  30.         {
  31.         int status=NX_SoundStopped;
  32.         id actual_sound=NULL;            // quiets compiler complaints
  33.         
  34.         //printf ("Sound ain't Null\n");
  35.         
  36.         if ([sound isKindOf:[Sound class]]) 
  37.             {actual_sound=sound;}
  38.         else if ([sound isKindOf:[SoundView class]])
  39.             {actual_sound=[sound soundBeingProcessed];}
  40.         status=[actual_sound status];
  41.         if (status==NX_SoundStopped||
  42.             status==NX_SoundInitialized||
  43.             status==NX_SoundFreed) 
  44.         {just_erase=1;}
  45.             
  46.         // Then modify the meter to match the sound    
  47.         
  48.         else if (status==NX_SoundRecordingPaused||
  49.                  status==NX_SoundRecording||
  50.                  status==NX_SoundRecordingPending)
  51.         {[self setToInput];}
  52.         
  53.         else if (status==NX_SoundPlayingPaused||
  54.                  status==NX_SoundPlaying||
  55.                  status==NX_SoundPlayingPending)
  56.         {[self setToOutput];}
  57.         
  58.         if ([actual_sound channelCount]>1)
  59.             {[self setStereo];}
  60.         else {[self setMono];}
  61.         }
  62.     
  63.  
  64.     
  65.     
  66.     
  67.     if (bezeled)
  68.         {
  69.         backgroundRect.origin.x        +=VOLUMEMETER_BACKGROUND_INSET; 
  70.         backgroundRect.size.width    -=VOLUMEMETER_BACKGROUND_INSET*2;
  71.         backgroundRect.origin.y        +=VOLUMEMETER_BACKGROUND_INSET; 
  72.         backgroundRect.size.height    -=VOLUMEMETER_BACKGROUND_INSET*2;
  73.         }
  74.     
  75.     if (!VOLUMEMETER_can_draw(&bounds)) return self;    // can't draw
  76.     //printf("Big enough\n");
  77.     if (bezeled) NXDrawGrayBezel(&bounds,NULL);
  78.  
  79.     if (running&&!just_erase)
  80.         {
  81.         //printf ("DRAWING!\n");
  82.         left=0;right=0;
  83.         
  84.         if (input&&input_device!=NULL) 
  85.             [input_device getPeakLeft:&left right:&right];
  86.         
  87.         if ((!input)&&output_device!=NULL)
  88.             [output_device getPeakLeft:&left right:&right];
  89.             
  90.         PSsetgray((left+right)/2.0);
  91.         NXRectFill(&backgroundRect);
  92.         }
  93.     just_erase=0;
  94.     NXPing();
  95.     if ([delegate respondsTo:@selector(meterDidUpdate:)])
  96.         [delegate meterDidUpdate:self];
  97.     return self;
  98.     }
  99.  
  100. @end