daily pastebin goal
61%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  PlayMidiDemoViewController.m
  3. //  PlayMidiDemo
  4. //
  5. //  Created by xhan on 9/9/09.
  6. //  Copyright In-Blue 2009. All rights reserved.
  7. //
  8.  
  9. #import "PlayMidiDemoViewController.h"
  10.  
  11.  
  12. @implementation PlayMidiDemoViewController
  13.  
  14. @synthesize status;
  15. @synthesize time;
  16.  
  17.  
  18.  
  19. void ERRCHECK(FMOD_RESULT result)
  20. {
  21.     if (result != FMOD_OK)
  22.     {
  23.         fprintf(stderr, "FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
  24.         exit(-1);
  25.     }
  26. }
  27.  
  28.  
  29.  
  30.  
  31.  
  32. - (void)viewDidLoad {
  33.     [super viewDidLoad];
  34.     system = NULL;
  35.     sound1  = NULL;
  36.     sound2  = NULL;
  37.     channel = NULL;
  38. }
  39.  
  40.  
  41.  
  42.  
  43. - (void)didReceiveMemoryWarning {
  44.     // Releases the view if it doesn't have a superview.
  45.     [super didReceiveMemoryWarning];
  46.    
  47.     // Release any cached data, images, etc that aren't in use.
  48. }
  49.  
  50. - (void)viewDidUnload {
  51.     // Release any retained subviews of the main view.
  52.     // e.g. self.myOutlet = nil;
  53. }
  54.  
  55.  
  56. - (void)dealloc {
  57.     [status release], status = nil;
  58.     [time release], time = nil;
  59.     [super dealloc];
  60. }
  61.  
  62. - (void)viewWillAppear:(BOOL)animated
  63. {
  64.     FMOD_RESULT   result        = FMOD_OK;
  65.     char          buffer[200]   = {0};
  66.     unsigned int  version       = 0;
  67.    
  68.     /*
  69.      Create a System object and initialize
  70.      */    
  71.     result = FMOD::System_Create(&system);
  72.     ERRCHECK(result);
  73.    
  74.     result = system->getVersion(&version);
  75.     ERRCHECK(result);
  76.    
  77.     if (version < FMOD_VERSION)
  78.     {
  79.         fprintf(stderr, "You are using an old version of FMOD %08x.  This program requires %08x\n", version, FMOD_VERSION);
  80.         exit(-1);
  81.     }
  82.    
  83.     result = system->init(32, FMOD_INIT_NORMAL | FMOD_INIT_ENABLE_PROFILE, NULL);
  84.     ERRCHECK(result);
  85.    
  86.    
  87.     // set up DLS file
  88.     FMOD_CREATESOUNDEXINFO   soundExInfo;
  89.     memset(&soundExInfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
  90.     soundExInfo.cbsize   = sizeof(FMOD_CREATESOUNDEXINFO);
  91.     char dlsName[200] = {0};
  92.     [[NSString stringWithFormat:@"%@/gm.dls", [[NSBundle mainBundle] resourcePath]] getCString:dlsName maxLength:200 encoding:NSASCIIStringEncoding];  
  93.     soundExInfo.dlsname  = dlsName;
  94.    
  95.         // midi one
  96.     [[NSString stringWithFormat:@"%@/Bass_sample.mid", [[NSBundle mainBundle] resourcePath]] getCString:buffer maxLength:200 encoding:NSASCIIStringEncoding];  
  97.  
  98.     result = system->createSound(buffer, FMOD_SOFTWARE | FMOD_CREATESTREAM, &soundExInfo, &sound1);
  99.  
  100. //    ERRCHECK(result);
  101.    
  102.     result = sound1->setMode(FMOD_LOOP_OFF);
  103. //    ERRCHECK(result);
  104.    
  105.     // midi two
  106.     [[NSString stringWithFormat:@"%@/Drum_sample.mid", [[NSBundle mainBundle] resourcePath]] getCString:buffer maxLength:200 encoding:NSASCIIStringEncoding];  
  107.    
  108.     result = system->createSound(buffer, FMOD_SOFTWARE | FMOD_CREATESTREAM, &soundExInfo, &sound2);
  109.     result = sound2->setMode(FMOD_LOOP_OFF);    
  110.  
  111.    
  112. //    timer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(timerUpdate:) userInfo:nil repeats:YES];
  113. }
  114.  
  115. - (IBAction)playSound1:(id)sender
  116. {
  117.     FMOD_RESULT result = FMOD_OK;
  118.    
  119.     result = system->playSound(FMOD_CHANNEL_FREE, sound1, false, &channel);
  120.     ERRCHECK(result);
  121. }
  122.  
  123.  
  124. - (IBAction)playSound2:(id)sender
  125. {
  126.     FMOD_RESULT result = FMOD_OK;
  127.    
  128.     result = system->playSound(FMOD_CHANNEL_FREE, sound2, false, &channel);
  129.     ERRCHECK(result);    
  130. }
  131.  
  132. - (void)timerUpdate:(NSTimer *)timer
  133. {
  134.    
  135. }
  136.  
  137. @end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top