3
ButtonTestActivity.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
26
package com.csounds.examples.tests;
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;
40
import com.csounds.CsoundObj;
41
import com.csounds.CsoundObjCompletionListener;
42
import com.csounds.examples.BaseCsoundActivity;
43
import com.csounds.examples.R;
45
public class ButtonTestActivity extends BaseCsoundActivity implements
46
CsoundObjCompletionListener {
48
ToggleButton startStopButton = null;
53
SeekBar durationSlider;
56
SeekBar sustainSlider;
57
SeekBar releaseSlider;
59
/** Called when the activity is first created. */
61
public void onCreate(Bundle savedInstanceState) {
62
super.onCreate(savedInstanceState);
63
setContentView(R.layout.button_test);
65
startStopButton = (ToggleButton) findViewById(R.id.onOffButton);
67
eventButton = (Button) findViewById(R.id.eventButton);
68
valueButton = (Button) findViewById(R.id.valueButton);
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);
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);
83
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
86
public void onCheckedChanged(CompoundButton buttonView,
89
String csd = getResourceFileAsString(R.raw.button_test);
90
File f = createTempFile(csd);
92
csoundObj.addSlider(durationSlider, "duration", .5,
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);
99
csoundObj.addButton(valueButton, "button1");
101
eventButton.setOnClickListener(new OnClickListener() {
104
public void onClick(View v) {
106
Log.d("TEST", "Event Button");
108
float value = durationSlider.getProgress() / (float)durationSlider.getMax();
111
float range = max - min;
112
value = (value * range) + min;
113
String event = String.format("i2 0 %f", value);
115
csoundObj.sendScore(event);
119
csoundObj.startCsound(f);
121
csoundObj.stopCsound();
130
public void csoundObjComplete(CsoundObj csoundObj) {
131
handler.post(new Runnable() {
133
startStopButton.setChecked(false);