Android Open Source - OpenSynth Arpeggio






From Project

Back to project page OpenSynth.

License

The source code is released under:

Apache License

If you think the Android project OpenSynth listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright 2013 Daisuke Fuji <daisuke@indigo-lab.com>
 * /*ww w .  j  ava2s.  com*/
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.thebends.synth;

public class Arpeggio implements Parameter {
    // Describes how to determine the next note
    public enum Step {
        UP,
        DOWN,
        UP_DOWN,
        RANDOM
    };

    private static final int kNotesPerOctave = 12;

    private KeyStack mKeys;
    private long mSample;
    private long mSamplesPerNote;
    private int mOctaves;
    private int mNote;
    private boolean mMovingUp;  // Only used by UP_DOWN
    private Step mStep;

    public Arpeggio(KeyStack keys) {
        mKeys = keys;
        mSample = 0;
        mSamplesPerNote = 1;
        mOctaves = 1;
        mNote = -1;
        mMovingUp = true;
        mStep = Step.UP;
    }

    public double getValue() {
        int note = getNote();
        if (note > 0) {
            return KeyStack.toFrequency(getNote());
        }
        return 0.0f;
    }

    public int getNote() {
        int size = mKeys.size();
        if (size <= 0) {
            return 0;
        }
        int max = mOctaves * size;
        if (mSample == 0) {
            if (mStep == Step.UP) {
                mNote = (mNote + 1) % max;
            } else if (mStep == Step.DOWN) {
                mNote--;
                if (mNote < 0) {
                    mNote = max - 1;
                }
            } else if (mStep == Step.UP_DOWN) {
                if (mMovingUp) {
                    mNote++;
                    if (mNote >= max - 1) {
                        mNote = max - 1;
                        mMovingUp = false;
                    }
                } else {
                    mNote--;
                    if (mNote <= 0) {
                        mMovingUp = true;
                        mNote = 0;
                    }
                }
            } else {
                mNote = (int)(Math.random() % max);
            }
        }
        mSample = (mSample + 1) % mSamplesPerNote;
        int octave = mNote / size;
        return octave * kNotesPerOctave + mKeys.getNote(mNote % size);
    }

    /*
     *  The number of octaves up to include
     */
    public void setOctaves(int count) {
        assert count >= 1;
        mOctaves = count;
    }

    public void setStep(Step step) {
        mStep = step;
    }

    public void setSamplesPerNote(long samples_per_note) {
        mSamplesPerNote = samples_per_note;
    }

    public void reset() {
        mSample = 0;
    }
}




Java Source Code List

com.google.synthesizer.android.widgets.piano.BlackPianoKey.java
com.google.synthesizer.android.widgets.piano.NotePianoKey.java
com.google.synthesizer.android.widgets.piano.OctavePianoKey.java
com.google.synthesizer.android.widgets.piano.PianoKey.java
com.google.synthesizer.android.widgets.piano.PianoViewListener.java
com.google.synthesizer.android.widgets.piano.PianoView.java
com.google.synthesizer.android.widgets.piano.WhitePianoKey.java
com.google.synthesizer.core.midi.MidiListener.java
com.google.synthesizer.core.music.Note.java
com.indigo_lab.android.opensynth.OpenSynthActivity.java
com.indigo_lab.android.opensynth.ViewPagerAdapter.java
com.indigo_lab.android.opensynth.view.ArpeggioView.java
com.indigo_lab.android.opensynth.view.ControllerView.java
com.indigo_lab.android.opensynth.view.EnvelopeView.java
com.indigo_lab.android.opensynth.view.FilterEnvelopeView.java
com.indigo_lab.android.opensynth.view.FilterView.java
com.indigo_lab.android.opensynth.view.ImageRadioButton.java
com.indigo_lab.android.opensynth.view.ModulationView.java
com.indigo_lab.android.opensynth.view.OscillatorDetailView.java
com.indigo_lab.android.opensynth.view.OscillatorView.java
com.indigo_lab.android.opensynth.view.RadioButton.java
com.indigo_lab.android.opensynth.view.VolumeEnvelopeView.java
org.thebends.synth.Arpeggio.java
org.thebends.synth.Controller.java
org.thebends.synth.Envelope.java
org.thebends.synth.FilterCutoff.java
org.thebends.synth.Filter.java
org.thebends.synth.FixedParameter.java
org.thebends.synth.KeyStack.java
org.thebends.synth.KeyboardOscillator.java
org.thebends.synth.LFO.java
org.thebends.synth.LagProcessor.java
org.thebends.synth.LowPassFilter.java
org.thebends.synth.MutableParameter.java
org.thebends.synth.Oscillator.java
org.thebends.synth.Parameter.java
org.thebends.synth.ResonantFilter.java
org.thebends.synth.SynthJni.java
org.thebends.synth.SynthTrack.java
org.thebends.synth.Volume.java