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

« back to all changes in this revision

Viewing changes to android/CsoundAndroidExamples/src/com/csounds/examples/tests/ButtonTestActivity.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
 ButtonTestActivity.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
package com.csounds.examples.tests;
 
27
 
 
28
import java.io.File;
 
29
 
 
30
import android.os.Bundle;
 
31
import android.util.Log;
 
32
import android.view.View;
 
33
import android.view.View.OnClickListener;
 
34
import android.widget.Button;
 
35
import android.widget.CompoundButton;
 
36
import android.widget.CompoundButton.OnCheckedChangeListener;
 
37
import android.widget.SeekBar;
 
38
import android.widget.ToggleButton;
 
39
 
 
40
import com.csounds.CsoundObj;
 
41
import com.csounds.CsoundObjCompletionListener;
 
42
import com.csounds.examples.BaseCsoundActivity;
 
43
import com.csounds.examples.R;
 
44
 
 
45
public class ButtonTestActivity extends BaseCsoundActivity implements
 
46
                CsoundObjCompletionListener {
 
47
        
 
48
        ToggleButton startStopButton = null;
 
49
 
 
50
        Button eventButton;
 
51
        Button valueButton;
 
52
        
 
53
        SeekBar durationSlider;
 
54
        SeekBar attackSlider;
 
55
        SeekBar decaySlider;
 
56
        SeekBar sustainSlider;
 
57
        SeekBar releaseSlider;
 
58
 
 
59
        /** Called when the activity is first created. */
 
60
        @Override
 
61
        public void onCreate(Bundle savedInstanceState) {
 
62
                super.onCreate(savedInstanceState);
 
63
                setContentView(R.layout.button_test);
 
64
 
 
65
                startStopButton = (ToggleButton) findViewById(R.id.onOffButton);
 
66
 
 
67
                eventButton = (Button) findViewById(R.id.eventButton);
 
68
                valueButton = (Button) findViewById(R.id.valueButton);
 
69
                
 
70
                durationSlider = (SeekBar) findViewById(R.id.durationSlider);
 
71
                attackSlider = (SeekBar) findViewById(R.id.attackSlider);
 
72
                decaySlider = (SeekBar) findViewById(R.id.decaySlider);
 
73
                sustainSlider = (SeekBar) findViewById(R.id.sustainSlider);
 
74
                releaseSlider = (SeekBar) findViewById(R.id.releaseSlider);
 
75
 
 
76
                setSeekBarValue(durationSlider, .5, 4, 1.5);
 
77
                setSeekBarValue(attackSlider, .001, 2, .05);
 
78
                setSeekBarValue(decaySlider, .05, 2, .05);
 
79
                setSeekBarValue(sustainSlider, 0, 1, .7);
 
80
                setSeekBarValue(releaseSlider, .05, 4, 1.5);
 
81
 
 
82
                startStopButton
 
83
                                .setOnCheckedChangeListener(new OnCheckedChangeListener() {
 
84
 
 
85
                                        @Override
 
86
                                        public void onCheckedChanged(CompoundButton buttonView,
 
87
                                                        boolean isChecked) {
 
88
                                                if (isChecked) {
 
89
                                                        String csd = getResourceFileAsString(R.raw.button_test);
 
90
                                                        File f = createTempFile(csd);
 
91
 
 
92
                                                        csoundObj.addSlider(durationSlider, "duration", .5,
 
93
                                                                        4);
 
94
                                                        csoundObj.addSlider(attackSlider, "attack", 0, 2);
 
95
                                                        csoundObj.addSlider(decaySlider, "decay", .05, 2);
 
96
                                                        csoundObj.addSlider(sustainSlider, "sustain", 0, 1);
 
97
                                                        csoundObj.addSlider(releaseSlider, "release", 0, 4);
 
98
 
 
99
                                                        csoundObj.addButton(valueButton, "button1");
 
100
                                                        
 
101
                                                        eventButton.setOnClickListener(new OnClickListener() {
 
102
                                                                
 
103
                                                                @Override
 
104
                                                                public void onClick(View v) {
 
105
                                                                        
 
106
                                                                        Log.d("TEST", "Event Button");
 
107
                                                                        
 
108
                                                                        float value = durationSlider.getProgress() / (float)durationSlider.getMax();
 
109
                                                                        float min = .5f;
 
110
                                                                        float max = 4f;
 
111
                                                                        float range = max - min;
 
112
                                                                        value = (value * range) + min;
 
113
                                                                        String event = String.format("i2 0 %f", value);
 
114
                                                                        
 
115
                                                                        csoundObj.sendScore(event);
 
116
                                                                }
 
117
                                                        });
 
118
                                                        
 
119
                                                        csoundObj.startCsound(f);
 
120
                                                } else {
 
121
                                                        csoundObj.stopCsound();
 
122
                                                }
 
123
 
 
124
                                        }
 
125
                                });
 
126
 
 
127
        }
 
128
 
 
129
        @Override
 
130
        public void csoundObjComplete(CsoundObj csoundObj) {
 
131
                handler.post(new Runnable() {
 
132
                        public void run() {
 
133
                                startStopButton.setChecked(false);
 
134
                        }
 
135
                });
 
136
        }
 
137
 
 
138
}