Skip to content

Commit 6117824

Browse files
author
Shaji Khan
committed
MIDI auto fill values
1 parent f7537b6 commit 6117824

3 files changed

Lines changed: 65 additions & 44 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: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.shajikhan.ladspa.amprack;
22

33
import static android.bluetooth.BluetoothDevice.ACTION_BOND_STATE_CHANGED;
4-
import static android.bluetooth.BluetoothDevice.DEVICE_TYPE_LE;
54
import static android.bluetooth.BluetoothDevice.EXTRA_BOND_STATE;
65
import static android.bluetooth.BluetoothDevice.EXTRA_DEVICE;
76
import static android.view.View.GONE;
@@ -15,7 +14,6 @@
1514
import androidx.appcompat.app.AppCompatActivity;
1615
import androidx.appcompat.app.AppCompatDelegate;
1716
import androidx.constraintlayout.widget.ConstraintLayout;
18-
import androidx.constraintlayout.widget.ConstraintSet;
1917
import androidx.core.app.ActivityCompat;
2018
import androidx.core.app.NotificationCompat;
2119
import androidx.core.app.NotificationManagerCompat;
@@ -39,8 +37,6 @@
3937
import android.app.ProgressDialog;
4038
import android.bluetooth.BluetoothAdapter;
4139
import android.bluetooth.BluetoothDevice;
42-
import android.bluetooth.BluetoothGatt;
43-
import android.bluetooth.BluetoothGattCallback;
4440
import android.bluetooth.le.ScanResult;
4541
import android.companion.AssociationInfo;
4642
import android.companion.AssociationRequest;
@@ -69,10 +65,7 @@
6965
import android.graphics.PorterDuffColorFilter;
7066
import android.graphics.RectF;
7167
import android.graphics.SurfaceTexture;
72-
import android.graphics.drawable.BitmapDrawable;
73-
import android.graphics.drawable.Drawable;
7468
import android.hardware.SensorManager;
75-
import android.hardware.camera2.CameraAccessException;
7669
import android.hardware.camera2.CameraCharacteristics;
7770
import android.hardware.camera2.params.StreamConfigurationMap;
7871
import android.media.AudioAttributes;
@@ -98,14 +91,12 @@
9891
import android.os.Handler;
9992
import android.os.Looper;
10093
import android.os.ParcelUuid;
101-
import android.os.Parcelable;
10294
import android.provider.MediaStore;
10395
import android.text.Editable;
10496
import android.text.TextWatcher;
10597
import android.util.ArraySet;
10698
import android.util.Log;
10799
import android.util.Size;
108-
import android.view.Display;
109100
import android.view.LayoutInflater;
110101
import android.view.MenuItem;
111102
import android.view.OrientationEventListener;
@@ -138,23 +129,18 @@
138129
import com.android.billingclient.api.BillingClient;
139130
import com.android.billingclient.api.BillingClientStateListener;
140131
import com.android.billingclient.api.BillingResult;
141-
import com.android.billingclient.api.ProductDetails;
142-
import com.android.billingclient.api.ProductDetailsResponseListener;
143132
import com.android.billingclient.api.Purchase;
144133
import com.android.billingclient.api.PurchasesResponseListener;
145134
import com.android.billingclient.api.PurchasesUpdatedListener;
146-
import com.android.billingclient.api.QueryProductDetailsParams;
147135
import com.google.android.material.bottomnavigation.BottomNavigationView;
148136
import com.google.android.material.button.MaterialButton;
149137
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
150138
import com.google.android.material.slider.Slider;
151139
import com.google.android.material.switchmaterial.SwitchMaterial;
152-
import com.google.common.collect.ImmutableList;
153140
import com.google.firebase.FirebaseApp;
154141
import com.google.firebase.analytics.FirebaseAnalytics;
155142
import com.google.firebase.auth.FirebaseAuth;
156143
import com.google.firebase.auth.FirebaseUser;
157-
import com.google.gson.JsonObject;
158144
import com.shajikhan.ladspa.amprack.databinding.ActivityMainBinding;
159145

160146
import org.json.JSONArray;
@@ -172,7 +158,6 @@
172158
import java.io.InputStream;
173159
import java.io.InputStreamReader;
174160
import java.io.OutputStream;
175-
import java.nio.ByteBuffer;
176161
import java.nio.file.Files;
177162
import java.text.SimpleDateFormat;
178163
import java.util.ArrayList;
@@ -181,7 +166,6 @@
181166
import java.util.HashMap;
182167
import java.util.HashSet;
183168
import java.util.Iterator;
184-
import java.util.LinkedList;
185169
import java.util.List;
186170
import java.util.Map;
187171
import java.util.Set;
@@ -277,6 +261,10 @@ public void onSend(byte[] data, int offset,
277261
boolean videoRecording = false ;
278262
static boolean tabletMode = false ;
279263
Camera2 camera2 ;
264+
Dialog midiAddDialog = null ;
265+
ConstraintLayout midiLayout = null ;
266+
EditText channelEdit = null, controlEdit = null ;
267+
280268
public static String price = "$2";
281269
MediaPlayerDialog mediaPlayerDialog = null;
282270
private OrientationEventListener orientationEventListener;
@@ -4562,12 +4550,15 @@ void setMidiControl (View view, int plugin, int control, MIDIControl.Type type,
45624550
midiControl.pluginControl = control ;
45634551
midiControl.view = view ;
45644552

4565-
View layout = getLayoutInflater().inflate(R.layout.midi_add_control, null);
4566-
((EditText) layout.findViewById(R.id.channel)).setText(channel);
4567-
((EditText) layout.findViewById(R.id.control)).setText(data1);
4553+
midiLayout = (ConstraintLayout) getLayoutInflater().inflate(R.layout.midi_add_control, null);
4554+
((EditText) midiLayout.findViewById(R.id.channel)).setText(channel);
4555+
((EditText) midiLayout.findViewById(R.id.control)).setText(data1);
4556+
4557+
channelEdit = midiLayout.findViewById(R.id.channel) ;
4558+
controlEdit = midiLayout.findViewById(R.id.control) ;
45684559

45694560
AlertDialog.Builder builder = new AlertDialog.Builder(this);
4570-
builder.setView(layout);
4561+
builder.setView(midiLayout);
45714562
if (scope == MIDIControl.Scope.PLUGIN)
45724563
builder.setTitle("Set MIDI Control for " + AudioEngine.getActivePluginName(plugin) + " " + AudioEngine.getControlName(plugin, control));
45734564
else
@@ -4579,8 +4570,8 @@ void setMidiControl (View view, int plugin, int control, MIDIControl.Type type,
45794570
public void onClick(DialogInterface dialog, int which) {
45804571
if (finalOld != null)
45814572
midiControls.remove(finalOld);
4582-
String channel = ((EditText) layout.findViewById(R.id.channel)).getText().toString();
4583-
String program = ((EditText) layout.findViewById(R.id.control)).getText().toString();
4573+
String channel = ((EditText) midiLayout.findViewById(R.id.channel)).getText().toString();
4574+
String program = ((EditText) midiLayout.findViewById(R.id.control)).getText().toString();
45844575

45854576
int ch = -1 ;
45864577
int pr = -1 ;
@@ -4598,6 +4589,7 @@ public void onClick(DialogInterface dialog, int which) {
45984589
midiControl.control = pr ;
45994590
midiControls.add(midiControl);
46004591

4592+
Toast.makeText(MainActivity.this, "MIDI control set successfully", Toast.LENGTH_SHORT).show();
46014593
Log.d(TAG, "[midi controls]: " + midiControls.toString());
46024594
if (scope == MIDIControl.Scope.GLOBAL) {
46034595
saveGlobalMidi();
@@ -4611,6 +4603,14 @@ public void onClick(DialogInterface dialog, int which) {
46114603

46124604
AlertDialog dialog = builder.create() ;
46134605

4606+
midiAddDialog = dialog ;
4607+
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
4608+
@Override
4609+
public void onDismiss(DialogInterface dialog) {
4610+
Log.i(TAG, "onDismiss: midi add dialog set to null");
4611+
midiAddDialog = null ;
4612+
}
4613+
});
46144614

46154615
dialog.show();
46164616
}
@@ -4627,6 +4627,10 @@ void processMIDIMessage (int channel, int data1, int data2) {
46274627
@Override
46284628
public void run() {
46294629
midiDisplay.setText(msg);
4630+
if (midiAddDialog != null) {
4631+
((EditText) midiAddDialog.findViewById(R.id.channel)).setText(String.valueOf(channel));
4632+
((EditText) midiAddDialog.findViewById(R.id.control)).setText(String.valueOf(data1));
4633+
}
46304634
}
46314635
});
46324636

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,51 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:layout_width="match_parent"
4-
android:layout_height="match_parent">
4+
android:layout_height="match_parent"
5+
xmlns:app="http://schemas.android.com/apk/res-auto">
56

67
<LinearLayout
8+
app:layout_constraintTop_toTopOf="parent"
9+
app:layout_constraintLeft_toLeftOf="parent"
10+
android:orientation="vertical"
711
android:layout_width="match_parent"
8-
android:layout_margin="20dp"
9-
android:layout_height="match_parent"
10-
android:orientation="horizontal">
11-
<TextView
12-
android:layout_width="wrap_content"
13-
android:layout_height="wrap_content"
14-
android:text="Channel"/>
15-
<EditText
16-
android:layout_weight="1"
17-
android:id="@+id/channel"
18-
android:layout_width="wrap_content"
19-
android:layout_height="wrap_content"
20-
android:inputType="number" />
12+
android:layout_height="wrap_content">
13+
2114
<TextView
15+
android:textAlignment="center"
2216
android:layout_width="wrap_content"
2317
android:layout_height="wrap_content"
24-
android:text="Control"/>
25-
<EditText
26-
android:id="@+id/control"
27-
android:layout_width="wrap_content"
28-
android:layout_weight="1"
29-
android:layout_height="wrap_content"
30-
android:inputType="number" />
18+
android:layout_gravity="center"
19+
android:layout_margin="10dp"
20+
android:fontFamily="@font/comfortaa"
21+
android:text="Trigger MIDI control to auto fill values"/>
22+
<LinearLayout
23+
android:layout_width="match_parent"
24+
android:layout_margin="20dp"
25+
android:layout_height="match_parent"
26+
android:orientation="horizontal">
27+
<TextView
28+
android:layout_width="wrap_content"
29+
android:layout_height="wrap_content"
30+
android:text="Channel"/>
31+
<EditText
32+
android:layout_weight="1"
33+
android:id="@+id/channel"
34+
android:layout_width="wrap_content"
35+
android:layout_height="wrap_content"
36+
android:inputType="number" />
37+
<TextView
38+
android:layout_width="wrap_content"
39+
android:layout_height="wrap_content"
40+
android:text="Control"/>
41+
<EditText
42+
android:id="@+id/control"
43+
android:layout_width="wrap_content"
44+
android:layout_weight="1"
45+
android:layout_height="wrap_content"
46+
android:inputType="number" />
3147

48+
</LinearLayout>
3249
</LinearLayout>
3350

3451
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)