// ------------------------------ ANDROID STUFF -------------------------------------- @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sing); mainButton = (Button) findViewById(R.id.mainButton); mainButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { onMainButtonClick(v); } }); // initialize right and left hands rightHand = new RightHand(); leftHand = new LeftHand(); // init state and init web view cur_state = states.INIT; initWebView(); // Initialize PD initSystemServices(); bindService(new Intent(this, PdService.class), pdConnection, BIND_AUTO_CREATE); pitchView = (PitchView) findViewById(R.id.pitch_view); pitchView.setCenterPitch(127); // //prepare for audio file recording // mFileName = Environment.getExternalStorageDirectory().getAbsolutePath(); // mFileName += "/audiorecordtest.3gp"; }
public void onMainButtonClick(View v) { try { switch (cur_state) { case INIT: // create and display root note // get new root note curRootNote = rightHand.getNewRootNote(); // display note in javascript notationWebView.loadUrl("javascript:createRoot()"); // send note for PD to play PdBase.sendFloat("midinote1", curRootNote); PdBase.sendBang("rootTrigger"); // prepare for next state, ask for guess note cur_state = states.GIVE_GUESS; // rename the android main button ((Button) v).setText(R.string.mainButtonGiveGuess); break; case GIVE_GUESS: curGuessNote = rightHand.getNewGuessNote(); // create and display guess note // notationWebView.loadUrl("javascript:createGuessNote(" + // rightHand.getCurrentMidiGuessNote() + ")"); notationWebView.loadUrl("javascript:createGuessNote()"); // start recording pitchView.setCenterPitch(curGuessNote % 12); // prepare for next state, ask for answer cur_state = states.PLAY_ANSWER; // rename the android main button ((Button) v).setText(R.string.mainButtonPlayAnswer); break; case PLAY_ANSWER: // play answer PdBase.sendFloat("midinote1", curGuessNote); PdBase.sendBang("rootTrigger"); // prepare for next state, ask for answer cur_state = states.START_OVER; ((Button) v).setText(R.string.mainButtonStartOver); break; case START_OVER: // reset webview rightHand.resetNotes(); notationWebView.loadUrl("javascript:reset()"); // prepare for next state cur_state = states.INIT; ((Button) v).setText(R.string.mainButtonGiveRoot); // reset pitch to max pitchView.setCenterPitch(127); break; default: Log.e(LOG_TAG, "ERROR-WRONGSTATE"); break; } } catch (Exception e) { Log.e(LOG_TAG, e.toString()); finish(); } }