Skip to content

Commit

Permalink
new latency tuner dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaji Khan committed Jun 5, 2024
1 parent 3612800 commit 6ce5aca
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 46 deletions.
127 changes: 87 additions & 40 deletions app/src/main/java/com/shajikhan/ladspa/amprack/Rack.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.util.Log;
import android.view.DragEvent;
import android.view.GestureDetector;
Expand Down Expand Up @@ -640,45 +641,8 @@ public boolean onMenuItemClick(MenuItem item) {
tuneLatency.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
MainActivity.toast(AudioEngine.tuneLatency());
return false;
}
});

MenuItem glitch = optionsMenu.getMenu().findItem(R.id.glitch);
glitch.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(@NonNull MenuItem item) {
if (! mainActivity.running)
return false;

AudioEngine.fixGlitches();
Toast.makeText(mainActivity,
String.format(
"Latency: %.0f, Buffer size: %d",
AudioEngine.getLatency(true) + AudioEngine.getLatency(false),
AudioEngine.getBufferSizeInFrames(false)
)
, Toast.LENGTH_SHORT).show();
return false;
}
});

MenuItem minimize = optionsMenu.getMenu().findItem(R.id.minimize);
minimize.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(@NonNull MenuItem item) {
if (! mainActivity.running)
return false;

AudioEngine.minimizeLatency();
Toast.makeText(mainActivity,
String.format(
"Latency: %.0f, Buffer size: %d",
AudioEngine.getLatency(true) + AudioEngine.getLatency(false),
AudioEngine.getBufferSizeInFrames(false)
)
, Toast.LENGTH_SHORT).show();
// MainActivity.toast(AudioEngine.tuneLatency());
latencyDialog();
return false;
}
});
Expand Down Expand Up @@ -1197,9 +1161,92 @@ public void patchMove (boolean up) {

public void latencyDialog () {
LinearLayout linearLayout = (LinearLayout) mainActivity.getLayoutInflater().inflate(R.layout.latency_tuner, null);
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(mainActivity);
AlertDialog.Builder builder = new AlertDialog.Builder(mainActivity);
builder.setTitle("Latency Tuner")
.setView(linearLayout)
.setPositiveButton("Close", null);

Button latency = linearLayout.findViewById(R.id.latency);
latency.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (! mainActivity.running) {
Toast.makeText(mainActivity, "Audio Engine not running", Toast.LENGTH_SHORT).show();
return;
}

latency.setText(
String.format( "%.0f ms",
AudioEngine.getLatency(true) +
AudioEngine.getLatency(false)
)
);
}
});

if (mainActivity.running)
latency.performClick();

Button ato = linearLayout.findViewById(R.id.autofix);
ato.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (! mainActivity.running) {
Toast.makeText(mainActivity, "Audio Engine not running", Toast.LENGTH_SHORT).show();
return;
}

AudioEngine.tuneLatency();
latency.performClick();
}
});

Button minimize = linearLayout.findViewById(R.id.minimize);
minimize.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (! mainActivity.running) {
Toast.makeText(mainActivity, "Audio Engine not running", Toast.LENGTH_SHORT).show();
return;
}

AudioEngine.minimizeLatency();
latency.performClick();
}
});

Button glitch = linearLayout.findViewById(R.id.glitch);
glitch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (! mainActivity.running) {
Toast.makeText(mainActivity, "Audio Engine not running", Toast.LENGTH_SHORT).show();
return;
}

AudioEngine.fixGlitches();
latency.performClick();
}
});

android.os.Handler handler = new Handler();
Runnable r = new Runnable() {
@Override
public void run() {
latency.performClick();
handler.postDelayed(this, 500);
}
};
handler.postDelayed(r, 500);

builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
Log.d(TAG, "onDismiss: closing handler");
handler.removeCallbacks(r);
}
});

builder.show();
}
}
17 changes: 11 additions & 6 deletions app/src/main/res/layout/latency_tuner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@
android:layout_height="match_parent">

<Button
android:background="@drawable/rounded_corners_transparent"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/latency"
android:background="@drawable/rounded_corners_transparent"
android:padding="10dp"
android:fontFamily="@font/gruppo"
android:text="20ms"
android:drawableLeft="@drawable/ic_baseline_refresh_24"
android:textSize="24dp"/>
android:textSize="34dp"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:text="Auto"
android:background="@drawable/rounded_corners_transparent"
android:padding="10dp"
android:id="@+id/autofix"
android:drawableLeft="@drawable/baseline_auto_fix_high_24"/>
<TextView
android:layout_width="wrap_content"
Expand All @@ -36,8 +38,9 @@
android:drawableLeft="@drawable/baseline_bolt_24"
android:layout_gravity="center"
android:text="Minimize Latency"
android:padding="10dp"
android:layout_marginTop="20dp"
android:background="@drawable/rounded_corners_transparent"/>
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -49,10 +52,12 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:id="@+id/glitch"
android:layout_marginTop="20dp"
android:text="Fix Glitches"
android:drawableLeft="@drawable/baseline_settings_suggest_24"
android:background="@drawable/rounded_corners_transparent"/>
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down

0 comments on commit 6ce5aca

Please sign in to comment.