home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Utilities / FileSpy-1.1-MIHS / cSounds.m < prev    next >
Encoding:
Text File  |  1996-09-22  |  2.7 KB  |  109 lines

  1. /*
  2.  *   This sourcecode is part of FileSpy, a logfile observing utility.
  3.  *   Copyright (C) 1996  Felix Rauch
  4.  *
  5.  *   This program is free software; you can redistribute it and/or modify
  6.  *   it under the terms of the GNU General Public License as published by
  7.  *   the Free Software Foundation; either version 2 of the License, or
  8.  *   (at your option) any later version.
  9.  *   
  10.  *   Notice that this program may not be possessed, used, copied,
  11.  *   distributed or modified by people having to do with nuclear
  12.  *   weapons. See the file CONDITIONS for details.
  13.  *
  14.  *   This program is distributed in the hope that it will be useful,
  15.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  *   GNU General Public License for more details.
  18.  *
  19.  *   You should have received a copy of the GNU General Public License
  20.  *   along with this program; if not, write to the Free Software
  21.  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  *
  23.  *   To contact the original author, try:
  24.  *   e-mail: Felix.Rauch@nice.ch
  25.  *   Traditional mail:    Felix Rauch
  26.  *            Sempacherstrasse 33
  27.  *            8032 Zurich
  28.  *            Switzerland
  29.  */
  30.  
  31. #import "Controller.h"
  32.  
  33. @implementation Controller(Sounds)
  34.  
  35. - soundClick:sender
  36. {
  37.     [self setSound:[sender stringValue]];
  38.     return self;
  39. }
  40.  
  41. - setSoundClick:sender
  42. {
  43.     id openPanel;
  44.     const char *const fileType[2] = {"snd", NULL};
  45.     const char *const *files;
  46.     char tmpfile[MAXFILENAMELENGHT];
  47.     const char *file = [soundTextField stringValue];
  48.  
  49.     if(file[0] == '\000')
  50.     file = "/NextLibrary/Sounds";
  51.     openPanel = [OpenPanel new];
  52.     [openPanel chooseDirectories:NO];
  53.     [openPanel allowMultipleFiles:NO];
  54.     if([openPanel runModalForDirectory:file file:NULL types:fileType] == NX_OKTAG) {
  55.     if((files = [openPanel filenames]) != (const char *const *)0) {
  56.         sprintf(tmpfile, "%s/%s", [openPanel directory], files[0]);
  57.         [self setSound:tmpfile];
  58.         [mySound play];
  59.         [soundTextField setStringValue:tmpfile];
  60.     }
  61.     }
  62.     return self;
  63. }
  64.  
  65. - setSound:(const char *)file
  66. {
  67.     if(file[0] == '\000') {    // use systembeep if no filename specified
  68.     if(mySound != nil) {
  69.         [mySound free];
  70.         mySound = nil;
  71.     }
  72.     return self;
  73.     }
  74.     if(mySound != nil) {
  75.     [mySound free];
  76.     mySound = nil;
  77.     }
  78.     mySound = [[Sound alloc] initFromSoundfile:file];
  79.     if(mySound == nil)
  80.     return self;
  81.     if(![mySound isPlayable]) {
  82.     [mySound free];
  83.     mySound = nil;
  84.     } else {
  85.     [(Sound *)mySound setName:file];
  86.     }
  87.  
  88.     return self;
  89. }
  90.  
  91. - nxbeep
  92. {
  93.     if(mySound != nil)
  94.     [mySound play];
  95.     else
  96.     NXBeep();
  97.     return self;
  98. }
  99.  
  100. - (const char *)soundName
  101. {
  102.     if(mySound != nil)
  103.     return [mySound name];
  104.     else
  105.     return "";
  106. }
  107.  
  108. @end
  109.