Skip to content

Commit 60b71f4

Browse files
author
Shaji Khan
committed
ble midi works!
1 parent 6a8bd88 commit 60b71f4

3 files changed

Lines changed: 40 additions & 8 deletions

File tree

.idea/deploymentTargetSelector.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/shajikhan/ladspa/amprack/MainActivity.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import android.app.NotificationChannel;
3636
import android.app.NotificationManager;
3737
import android.app.PendingIntent;
38+
import android.bluetooth.BluetoothAdapter;
3839
import android.bluetooth.BluetoothDevice;
3940
import android.bluetooth.BluetoothGatt;
4041
import android.bluetooth.BluetoothGattCallback;
@@ -497,9 +498,22 @@ protected void onCreate(Bundle savedInstanceState) {
497498
defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
498499
headphoneWarning = defaultSharedPreferences.getBoolean("headphone-warning", true);
499500

501+
midiManager = (MidiManager)context.getSystemService(Context.MIDI_SERVICE);
502+
String mac = defaultSharedPreferences.getString("last_bt", null);
503+
if (mac != null) {
504+
deviceToPair = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(mac);
505+
if (deviceToPair != null) {
506+
midiManager.openBluetoothDevice(deviceToPair, new MidiManager.OnDeviceOpenedListener() {
507+
@Override
508+
public void onDeviceOpened(MidiDevice device) {
509+
510+
}
511+
}, null);
512+
}
513+
}
514+
500515
midiControls = new ArrayList<>();
501516
midiReciever = new MyReceiver(this);
502-
midiManager = (MidiManager)context.getSystemService(Context.MIDI_SERVICE);
503517
MidiDeviceInfo[] midiDeviceInfos = midiManager.getDevices();
504518
Log.d(TAG, String.format ("[midi] found devices: %d", midiDeviceInfos.length));
505519
for (MidiDeviceInfo midiDeviceInfo: midiDeviceInfos) {
@@ -525,14 +539,20 @@ protected void onCreate(Bundle savedInstanceState) {
525539
midiOutputPort = device.openOutputPort(finalOutputPort);
526540
Log.d(TAG, String.format ("[midi] port opened: port %d", midiOutputPort.getPortNumber()));
527541
midiOutputPort.connect(midiReciever);
528-
(findViewById(R.id.midi_icon)).setVisibility(VISIBLE);
529-
542+
mainActivity.runOnUiThread(new Runnable() {
543+
@Override
544+
public void run() {
545+
if (deviceToPair == null)
546+
(findViewById(R.id.midi_icon)).setVisibility(VISIBLE);
547+
else
548+
(findViewById(R.id.bt_icon)).setVisibility(VISIBLE);
549+
}
550+
});
530551
}, null);
531552
}
532553

533554
}
534555

535-
536556
Log.d(TAG, "onCreate: " + String.format("" +
537557
"%d: %d", BuildConfig.VERSION_CODE, defaultSharedPreferences.getInt("currentVersion", 0)));
538558
// if (BuildConfig.VERSION_CODE > defaultSharedPreferences.getInt("currentVersion", 0)) {
@@ -2102,6 +2122,7 @@ public void run() {
21022122
// });
21032123
Log.i(TAG, "onActivityResult: bluetooth device connected");
21042124
// ... Continue interacting with the paired device.
2125+
defaultSharedPreferences.edit().putString("last_bt", deviceToPair.getAddress()).apply();
21052126
midiManager.openBluetoothDevice(deviceToPair, new MidiManager.OnDeviceOpenedListener() {
21062127
@Override
21072128
public void onDeviceOpened(MidiDevice device) {
@@ -2196,6 +2217,11 @@ public void run() {
21962217
mainActivity.rack.toggleVideo.setChecked(false);
21972218
// mainActivity.rack.toggleVideo.setChecked(true);
21982219
}
2220+
2221+
if (PERMISSION_REQUEST_CODE_BLUETOOTH == requestCode &&
2222+
grantResults[0] == PackageManager.PERMISSION_GRANTED) {
2223+
scanBLE();
2224+
}
21992225
}
22002226

22012227
public static int getDominantColor(Bitmap bitmap) {

app/src/main/res/layout/rack.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,22 @@
6666
android:layout_height="wrap_content"/>
6767

6868
<ImageView
69+
android:scaleType="center"
70+
android:scaleX="1.5"
71+
android:scaleY="1.5"
72+
android:visibility="gone"
6973
android:layout_width="wrap_content"
7074
android:layout_height="wrap_content"
7175
android:src="@drawable/baseline_blur_circular_24"
72-
android:layout_marginTop="10dp"
73-
android:visibility="gone"
76+
android:layout_margin="10dp"
7477
android:id="@+id/midi_icon"/>
7578

7679
<ImageView
80+
android:scaleType="center"
81+
android:scaleX="1.2"
82+
android:scaleY="1.2"
7783
android:visibility="gone"
78-
android:layout_marginTop="10dp"
84+
android:layout_margin="10dp"
7985
android:layout_width="wrap_content"
8086
android:layout_height="wrap_content"
8187
android:src="@drawable/baseline_bluetooth_connected_24"

0 commit comments

Comments
 (0)