~ubuntu-branches/ubuntu/precise/csound/precise

« back to all changes in this revision

Viewing changes to android/CsoundAndroidExamples/src/com/csounds/examples/BaseCsoundActivity.java

  • Committer: Package Import Robot
  • Author(s): Felipe Sateler
  • Date: 2012-04-19 09:26:46 UTC
  • mfrom: (3.2.19 sid)
  • Revision ID: package-import@ubuntu.com-20120419092646-96xbj1n6atuqosk2
Tags: 1:5.17.6~dfsg-1
* New upstream release
 - Do not build the wiimote opcodes (we need wiiuse).
* Add new API function to symbols file
* Disable lua opcodes, they were broken. Requires OpenMP to be enabled.
* Backport fixes from upstream:
  - Link dssi4cs with dl. Backport
  - Fix building of CsoundAC

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 
 
3
 BaseCsoundActivity.java:
 
4
 
 
5
 Copyright (C) 2011 Victor Lazzarini, Steven Yi
 
6
 
 
7
 This file is part of Csound Android Examples.
 
8
 
 
9
 The Csound Android Examples is free software; you can redistribute it
 
10
 and/or modify it under the terms of the GNU Lesser General Public
 
11
 License as published by the Free Software Foundation; either
 
12
 version 2.1 of the License, or (at your option) any later version.   
 
13
 
 
14
 Csound 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 Lesser General Public License for more details.
 
18
 
 
19
 You should have received a copy of the GNU Lesser General Public
 
20
 License along with Csound; if not, write to the Free Software
 
21
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 
22
 02111-1307 USA
 
23
 
 
24
 */
 
25
 
 
26
 
 
27
package com.csounds.examples;
 
28
 
 
29
import java.io.BufferedReader;
 
30
import java.io.File;
 
31
import java.io.FileOutputStream;
 
32
import java.io.IOException;
 
33
import java.io.InputStream;
 
34
import java.io.InputStreamReader;
 
35
 
 
36
import android.app.Activity;
 
37
import android.os.Bundle;
 
38
import android.os.Handler;
 
39
import android.widget.SeekBar;
 
40
 
 
41
import com.csounds.CsoundObj;
 
42
 
 
43
public class BaseCsoundActivity extends Activity {
 
44
        
 
45
        protected CsoundObj csoundObj = new CsoundObj();
 
46
        protected Handler handler = new Handler();
 
47
        
 
48
        @Override
 
49
        public void onCreate(Bundle savedInstanceState) {
 
50
                super.onCreate(savedInstanceState);
 
51
        }
 
52
        
 
53
        @Override
 
54
        protected void onDestroy() {
 
55
                // TODO Auto-generated method stub
 
56
                super.onDestroy();
 
57
                csoundObj.stopCsound();
 
58
                
 
59
        }
 
60
        
 
61
        public void setSeekBarValue(SeekBar seekBar, double min, double max, double value) {
 
62
                double range = max - min;
 
63
                double percent = (value - min) / range;
 
64
                
 
65
                seekBar.setProgress((int)(percent * seekBar.getMax()));
 
66
        }
 
67
 
 
68
        
 
69
        protected String getResourceFileAsString(int resId) {
 
70
                StringBuilder str = new StringBuilder();
 
71
                
 
72
                InputStream is = getResources().openRawResource(resId);
 
73
                BufferedReader r = new BufferedReader(new InputStreamReader(is));
 
74
                String line;
 
75
                
 
76
                try {
 
77
                        while ((line = r.readLine()) != null) {
 
78
                                str.append(line).append("\n");
 
79
                        }
 
80
                } catch (IOException ios) {
 
81
 
 
82
                }
 
83
                
 
84
                return str.toString();
 
85
        }
 
86
 
 
87
        protected File createTempFile(String csd) {
 
88
                File f = null;
 
89
                
 
90
                try {
 
91
                        f = File.createTempFile("temp", ".csd", this.getCacheDir());
 
92
                        FileOutputStream fos = new FileOutputStream(f);
 
93
                        fos.write(csd.getBytes());
 
94
                        fos.close();
 
95
                } catch (IOException e) {
 
96
                        // TODO Auto-generated catch block
 
97
                        e.printStackTrace();
 
98
                }
 
99
                
 
100
                return f;
 
101
        }
 
102
}