1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.bluetoothmidiservice;
18 
19 import android.media.midi.MidiReceiver;
20 import android.util.Log;
21 
22 import com.android.internal.midi.MidiFramer;
23 
24 import java.util.ArrayList;
25 
26 class AccumulatingMidiReceiver extends MidiReceiver {
27     private static final String TAG = "AccumulatingMidiReceiver";
28     ArrayList<byte[]> mBuffers = new ArrayList<byte[]>();
29     ArrayList<Long> mTimestamps = new ArrayList<Long>();
30 
onSend(byte[] buffer, int offset, int count, long timestamp)31     public void onSend(byte[] buffer, int offset, int count, long timestamp) {
32         Log.d(TAG, "onSend() passed " + MidiFramer.formatMidiData(buffer, offset, count));
33         byte[] actualRow = new byte[count];
34         System.arraycopy(buffer, offset, actualRow, 0, count);
35         mBuffers.add(actualRow);
36         mTimestamps.add(timestamp);
37     }
38 
getBuffers()39     byte[][] getBuffers() {
40         return mBuffers.toArray(new byte[mBuffers.size()][]);
41     }
42 
getTimestamps()43     Long[] getTimestamps() {
44         return mTimestamps.toArray(new Long[mTimestamps.size()]);
45     }
46 }
47 
48