Skip to content

Commit

Permalink
Make notifications specific to ContinuousHardwareControl
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwig-thomas committed Jan 18, 2024
1 parent f0aadaa commit 7f7dfc4
Showing 1 changed file with 36 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.bitwig.extension.controller.api.BrowserResultsItem;
import com.bitwig.extension.controller.api.ClipLauncherSlot;
import com.bitwig.extension.controller.api.ClipLauncherSlotBank;
import com.bitwig.extension.controller.api.ContinuousHardwareControl;
import com.bitwig.extension.controller.api.ControllerHost;
import com.bitwig.extension.controller.api.CursorBrowserFilterItem;
import com.bitwig.extension.controller.api.CursorDevice;
Expand All @@ -38,7 +39,6 @@
import com.bitwig.extension.controller.api.RelativeHardwareKnob;
import com.bitwig.extension.controller.api.Scene;
import com.bitwig.extension.controller.api.SceneBank;
import com.bitwig.extension.controller.api.StringValue;
import com.bitwig.extension.controller.api.Track;
import com.bitwig.extension.controller.api.TrackBank;
import com.bitwig.extension.controller.api.Transport;
Expand Down Expand Up @@ -294,13 +294,13 @@ protected void onDeactivate()
};
mBrowserLayer = new Layer(mLayers, "Browser");

mNotificationLayer = new Layer(mLayers, "Notifications");
mAdjustingContinuousHardwareControlNotificationLayer = new Layer(mLayers, "Notifications");

initBaseLayer();
initDAWLayer();
initBrowserLayer();
initMultiLayer();
initNotificationLayer();
initAdjustingContinuousHardwareControlNotificationLayer();


mBaseLayer.activate();
Expand Down Expand Up @@ -511,85 +511,91 @@ private void initMultiLayer()
});
}

private void initNotificationLayer()
private void initAdjustingContinuousHardwareControlNotificationLayer()
{
mNotificationLayer.showText(this::getNotificationTopLine, this::getNotificationBottomLine);
mAdjustingContinuousHardwareControlNotificationLayer.showText(
this::getAdjustingContinuousHardwareControlNotificationTopLine,
this::getAdjustingContinuousHardwareControlNotificationBottomLine);

for (final RelativeHardwareControl encoder : mEncoders)
{
encoder.isUpdatingTargetValue().markInterested();
encoder.targetName().markInterested();
encoder.targetDisplayedValue().markInterested();
encoder.isBeingTouched().markInterested();
encoder.targetValue().addValueObserver((v) -> {
if (encoder.isUpdatingTargetValue().get())
showNotificationOnDisplay(encoder.targetName(), encoder.targetDisplayedValue());
showAdjustingContinuousHardwareControlNotification(encoder);
});
}

for (final AbsoluteHardwareControl fader : mFaders)
{
fader.targetName().markInterested();
fader.targetDisplayedValue().markInterested();
fader.value().addValueObserver((v) -> showNotificationOnDisplay(fader.targetName(), fader.targetDisplayedValue()));
fader.value().addValueObserver((v) -> showAdjustingContinuousHardwareControlNotification(fader));
}
}

private void showNotificationOnDisplay(final StringValue topRowText, final StringValue bottomRowText)
private void showAdjustingContinuousHardwareControlNotification(final ContinuousHardwareControl<?> control)
{
final int notificationDurationInMs = 500;

mNotificationTopRowText = topRowText;
mNotificationBottomRowText = bottomRowText;
mContinuousHardwareControlThatIsBeingAdjusted = control;

// Set end time for notification. If there is an active notification, we will respect the new end time.
mHideNotificationTime = System.currentTimeMillis() + notificationDurationInMs;
mHideAdjustingContinuousHardwareControlNotificationTime = System.currentTimeMillis() + notificationDurationInMs;

// Enable notification layer.
if (!mNotificationLayer.isActive())
if (!mAdjustingContinuousHardwareControlNotificationLayer.isActive())
{
mNotificationLayer.activate();
scheduleHideNotificationTask(mHideNotificationTime, notificationDurationInMs);
mAdjustingContinuousHardwareControlNotificationLayer.activate();
scheduleHideAdjustingContinuousHardwareControlNotificationTask(mHideAdjustingContinuousHardwareControlNotificationTime, notificationDurationInMs);
}
}

private void scheduleHideNotificationTask(final long hideNotificationTime, final int durationInMs)
private void scheduleHideAdjustingContinuousHardwareControlNotificationTask(final long hideNotificationTime, final int durationInMs)
{
if (durationInMs <= 0)
{
hideNotification();
hideAdjustingContinuousHardwareControlNotification();
return;
}

getHost().scheduleTask(() -> {
if (hideNotificationTime == mHideNotificationTime)
if (hideNotificationTime == mHideAdjustingContinuousHardwareControlNotificationTime)
{
// No other notification was shown in between
hideNotification();
hideAdjustingContinuousHardwareControlNotification();
}
else
{
// Another notification was shown since this task was scheduled. That means we should not hide the
// notification now, but schedule another task.
final long remainingTimeInMs = mHideNotificationTime - System.currentTimeMillis();
scheduleHideNotificationTask(mHideNotificationTime, (int) remainingTimeInMs);
final long remainingTimeInMs = mHideAdjustingContinuousHardwareControlNotificationTime - System.currentTimeMillis();
scheduleHideAdjustingContinuousHardwareControlNotificationTask(
mHideAdjustingContinuousHardwareControlNotificationTime,
(int) remainingTimeInMs);
}
}, durationInMs);
}

private void hideNotification()
private void hideAdjustingContinuousHardwareControlNotification()
{
mNotificationLayer.deactivate();
mAdjustingContinuousHardwareControlNotificationLayer.deactivate();
}

private String getNotificationTopLine()
private String getAdjustingContinuousHardwareControlNotificationTopLine()
{
return mNotificationTopRowText != null ? mNotificationTopRowText.getLimited(8) : "";
return mContinuousHardwareControlThatIsBeingAdjusted != null
? mContinuousHardwareControlThatIsBeingAdjusted.targetName().getLimited(8)
: "";
}

private String getNotificationBottomLine()
private String getAdjustingContinuousHardwareControlNotificationBottomLine()
{
return mNotificationBottomRowText != null ? mNotificationBottomRowText.getLimited(8) : "";
return mContinuousHardwareControlThatIsBeingAdjusted != null
? mContinuousHardwareControlThatIsBeingAdjusted.targetDisplayedValue().getLimited(8)
: "";
}

@Override
Expand Down Expand Up @@ -929,13 +935,11 @@ private void clearDisplay()

private Layer mDAWLayer;

private Layer mNotificationLayer;
private Layer mAdjustingContinuousHardwareControlNotificationLayer;

private StringValue mNotificationTopRowText;
private ContinuousHardwareControl<?> mContinuousHardwareControlThatIsBeingAdjusted;

private StringValue mNotificationBottomRowText;

private long mHideNotificationTime;
private long mHideAdjustingContinuousHardwareControlNotificationTime;

private Layer mBrowserLayer;

Expand Down

0 comments on commit 7f7dfc4

Please sign in to comment.