Examples' Makefiles are completed and tested.
[Faustine.git] / interpretor / preprocessor / faust-0.9.47mr3 / architecture / iPhone / iPhoneAppDelegate.mm
1 /************************************************************************
2 ************************************************************************
3 FAUST Architecture File
4 Copyright (C) 2003-2011 GRAME, Centre National de Creation Musicale
5 ---------------------------------------------------------------------
6
7 This is sample code. This file is provided as an example of minimal
8 FAUST architecture file. Redistribution and use in source and binary
9 forms, with or without modification, in part or in full are permitted.
10 In particular you can create a derived work of this FAUST architecture
11 and distribute that work under terms of your choice.
12
13 This sample code is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 ************************************************************************
17 ************************************************************************/
18
19 #import "iPhoneAppDelegate.h"
20 #import "iPhoneViewController.h"
21 #include "iphone-faust.h"
22
23
24 @implementation iPhoneAppDelegate
25
26 @synthesize window;
27 @synthesize viewController;
28
29 TiPhoneCoreAudioRenderer* audio_device = NULL;
30 UI* interface = NULL;
31 MY_Meta metadata;
32 char rcfilename[256];
33
34 - (void)applicationDidFinishLaunching:(UIApplication *)application
35 {
36 DSP.metadata(&metadata);
37
38 interface = new CocoaUI(window, viewController, &metadata);
39 audio_device = new TiPhoneCoreAudioRenderer(DSP.getNumInputs(), DSP.getNumOutputs());
40
41 long srate = 44100;
42 int fpb = 256;
43
44 DSP.init(long(srate));
45 DSP.buildUserInterface(interface);
46
47 const char* home = getenv ("HOME");
48 const char* name = (*metadata.find("name")).second;
49 if (home == 0)
50 home = ".";
51 snprintf(rcfilename, 256, "%s/Library/Caches/%s", home, name);
52 interface->recallState(rcfilename);
53
54 if (audio_device->Open(fpb, srate) < 0) {
55 printf("Cannot open CoreAudio device\n");
56 goto error;
57 }
58
59 if (audio_device->Start() < 0) {
60 printf("Cannot start CoreAudio device\n");
61 goto error;
62 }
63
64 return;
65
66 error:
67 delete interface;
68 delete audio_device;
69 }
70
71 - (void)applicationWillTerminate:(UIApplication *)application
72 {
73 interface->saveState(rcfilename);
74 }
75
76 - (void)dealloc
77 {
78 audio_device->Stop();
79 audio_device->Close();
80 delete audio_device;
81 delete interface;
82 [super dealloc];
83 }
84
85 @end