Example #1
0
  // ------------------------------ PUREDATA STUFF --------------------------------------
  private void initPd() throws IOException {

    // Configure the audio glue
    int sampleRate;
    sampleRate = AudioParameters.suggestSampleRate();
    // IF EMULATOR USE THIS
    // TODO find way to test for emulator
    sampleRate = 8000;

    // PdAudio.initAudio(sampleRate, 0, 2, 8, true);
    pdService.initAudio(sampleRate, 1, 2, 10.0f);
    pdService.startAudio();
    start();

    // Create and install the dispatcher
    dispatcher = new PdUiDispatcher();
    dispatcher.addListener(
        "pitch",
        new PdListener.Adapter() {
          @Override
          public void receiveFloat(String source, final float x) {
            if (m_fCurAmplitude > 60) pitchView.setCurrentPitch(x % 12);
            else pitchView.setCurrentPitch(0);
          }
        });

    dispatcher.addListener(
        "amplitude",
        new PdListener.Adapter() {
          @Override
          public void receiveFloat(String source, final float amplitude) {
            m_fCurAmplitude = amplitude;
          }
        });

    PdBase.setReceiver(dispatcher);
  }
Example #2
0
 private void loadPatch() throws IOException {
   File dir = getFilesDir();
   IoUtils.extractZipResource(getResources().openRawResource(R.raw.solfege_s_trigger), dir, true);
   File patchFile = new File(dir, "solfege.pd");
   int val = PdBase.openPatch(patchFile.getAbsolutePath());
 }
Example #3
0
  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();
    }
  }