3
BaseCsoundActivity.java:
5
Copyright (C) 2011 Victor Lazzarini, Steven Yi
7
This file is part of Csound Android Examples.
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.
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.
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
27
package com.csounds.examples;
29
import java.io.BufferedReader;
31
import java.io.FileOutputStream;
32
import java.io.IOException;
33
import java.io.InputStream;
34
import java.io.InputStreamReader;
36
import android.app.Activity;
37
import android.os.Bundle;
38
import android.os.Handler;
39
import android.widget.SeekBar;
41
import com.csounds.CsoundObj;
43
public class BaseCsoundActivity extends Activity {
45
protected CsoundObj csoundObj = new CsoundObj();
46
protected Handler handler = new Handler();
49
public void onCreate(Bundle savedInstanceState) {
50
super.onCreate(savedInstanceState);
54
protected void onDestroy() {
55
// TODO Auto-generated method stub
57
csoundObj.stopCsound();
61
public void setSeekBarValue(SeekBar seekBar, double min, double max, double value) {
62
double range = max - min;
63
double percent = (value - min) / range;
65
seekBar.setProgress((int)(percent * seekBar.getMax()));
69
protected String getResourceFileAsString(int resId) {
70
StringBuilder str = new StringBuilder();
72
InputStream is = getResources().openRawResource(resId);
73
BufferedReader r = new BufferedReader(new InputStreamReader(is));
77
while ((line = r.readLine()) != null) {
78
str.append(line).append("\n");
80
} catch (IOException ios) {
84
return str.toString();
87
protected File createTempFile(String csd) {
91
f = File.createTempFile("temp", ".csd", this.getCacheDir());
92
FileOutputStream fos = new FileOutputStream(f);
93
fos.write(csd.getBytes());
95
} catch (IOException e) {
96
// TODO Auto-generated catch block