@ -86,15 +86,6 @@ public class SynthesizerService extends Service {
params . bufferSize = 64 ;
params . bufferSize = 64 ;
androidGlue_ = new AndroidGlue ( ) ;
androidGlue_ = new AndroidGlue ( ) ;
midiListener_ = new MessageForwarder ( androidGlue_ ) {
@Override
public void onController ( int channel , int control , int value ) {
super . onController ( channel , control , value ) ;
if ( onCcListener_ ! = null ) {
onCcListener_ . onCcChange ( channel , control , value ) ;
}
}
} ;
androidGlue_ . start ( params . sampleRate , params . bufferSize ) ;
androidGlue_ . start ( params . sampleRate , params . bufferSize ) ;
InputStream patchIs = getResources ( ) . openRawResource ( R . raw . rom1a ) ;
InputStream patchIs = getResources ( ) . openRawResource ( R . raw . rom1a ) ;
byte [ ] patchData = new byte [ 4104 ] ;
byte [ ] patchData = new byte [ 4104 ] ;
@ -109,6 +100,31 @@ public class SynthesizerService extends Service {
Log . e ( getClass ( ) . getName ( ) , "loading patches failed" ) ;
Log . e ( getClass ( ) . getName ( ) , "loading patches failed" ) ;
}
}
}
}
midiListener_ = new MessageForwarder ( androidGlue_ ) {
@Override
public void onController ( int channel , int control , int value ) {
super . onController ( channel , control , value ) ;
if ( onCcListener_ ! = null ) {
onCcListener_ . onCcChange ( channel , control , value ) ;
}
}
@Override
public void onNoteOn ( int channel , int note , int velocity ) {
super . onNoteOn ( channel , note , velocity ) ;
if ( onNoteOnListener_ ! = null ) {
onNoteOnListener_ . onNote ( channel , note , velocity ) ;
}
}
@Override
public void onNoteOff ( int channel , int note , int velocity ) {
super . onNoteOff ( channel , note , velocity ) ;
if ( onNoteOffListener_ ! = null ) {
onNoteOffListener_ . onNote ( channel , note , velocity ) ;
}
}
} ;
androidGlue_ . setPlayState ( true ) ;
androidGlue_ . setPlayState ( true ) ;
if ( Build . VERSION . SDK_INT > = Build . VERSION_CODES . HONEYCOMB_MR1 ) {
if ( Build . VERSION . SDK_INT > = Build . VERSION_CODES . HONEYCOMB_MR1 ) {
IntentFilter filter = new IntentFilter ( UsbManager . ACTION_USB_DEVICE_DETACHED ) ;
IntentFilter filter = new IntentFilter ( UsbManager . ACTION_USB_DEVICE_DETACHED ) ;
@ -272,14 +288,24 @@ public class SynthesizerService extends Service {
}
}
} ;
} ;
// There's a pretty good case to be made this should just tee a MidiListener instead
public interface OnCcListener {
public interface OnCcListener {
abstract void onCcChange ( int channel , int cc , int value ) ;
abstract void onCcChange ( int channel , int cc , int value ) ;
}
}
public interface OnNoteListener {
abstract void onNote ( int channel , int note , int velocity ) ;
}
public void setOnCcListener ( OnCcListener onCcListener ) {
public void setOnCcListener ( OnCcListener onCcListener ) {
onCcListener_ = onCcListener ;
onCcListener_ = onCcListener ;
}
}
public void setOnNoteListeners ( OnNoteListener onNoteOn , OnNoteListener onNoteOff ) {
onNoteOnListener_ = onNoteOn ;
onNoteOffListener_ = onNoteOff ;
}
private MidiListener midiListener_ ;
private MidiListener midiListener_ ;
// Binder to use for Activities in this process.
// Binder to use for Activities in this process.
@ -298,4 +324,6 @@ public class SynthesizerService extends Service {
// Plumbing for MIDI events
// Plumbing for MIDI events
private OnCcListener onCcListener_ ;
private OnCcListener onCcListener_ ;
private OnNoteListener onNoteOnListener_ ;
private OnNoteListener onNoteOffListener_ ;
}
}