Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions playground-template/control.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ function hideBackingTrack(at) {


async function showBackingTrack(at) {
if(!at.score.backingTrack) {
hideBackingTrack();
return;
}

const audioElement = at.player.output.audioElement;
if(audioElement !== backingTrackAudioElement) {
Expand Down
2 changes: 1 addition & 1 deletion playground-template/youtube.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<head>
<meta charset="utf-8" />
<title>AlphaTab Control Demo</title>
<title>AlphaTab Youtube Sync</title>

<script src="/node_modules/@popperjs/core/dist/umd/popper.min.js"></script>
<script src="/node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
Expand Down
9 changes: 6 additions & 3 deletions src.csharp/AlphaTab.Windows/DelegatedEventEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ public DelegatedEventEmitter(Action<Action> on, Action<Action> off)
_off = off;
}

public void On(Action value)
public System.Action On(Action value)
{
_on(value);
return () => _off(value);
}

public void Off(Action value)
Expand All @@ -35,19 +36,21 @@ public DelegatedEventEmitter(Action<Action<T>> on, Action<Action<T>> off)
_off = off;
}

public void On(Action value)
public System.Action On(Action value)
{
// not used internally
return () => {};
}

public void Off(Action value)
{
// not used internally
}

public void On(Action<T> value)
public System.Action On(Action<T> value)
{
_on(value);
return () => _off(value);
}

public void Off(Action<T> value)
Expand Down
5 changes: 3 additions & 2 deletions src.csharp/AlphaTab/EventEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace AlphaTab;

partial interface IEventEmitterOfT<T>
{
void On(System.Action value);
System.Action On(System.Action value);
void Off(System.Action value);
}

Expand All @@ -14,14 +14,15 @@ partial class EventEmitterOfT<T>
new System.Collections.Generic.Dictionary<System.Action, System.Action<T>>();

[Obsolete("Use event registration overload with parameter.", false)]
public void On(System.Action value)
public System.Action On(System.Action value)
{
var wrapper = new Action<T>(_=>
{
value();
});
_wrappers[value] = wrapper;
On(wrapper);
return () => Off(value);
}

[Obsolete("Use event unregistration with parameter.", false)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ internal class AndroidUiFacade : IUiFacade<AlphaTabView> {

rootContainerBecameVisible = object : IEventEmitter,
ViewTreeObserver.OnGlobalLayoutListener, View.OnLayoutChangeListener {
override fun on(value: () -> Unit) {
override fun on(value: () -> Unit): () -> Unit {
if (rootContainer.isVisible) {
value()
} else {
outerScroll.viewTreeObserver.addOnGlobalLayoutListener(this)
outerScroll.addOnLayoutChangeListener(this)
}
return fun() { off(value) }
}

override fun off(value: () -> Unit) {
Expand Down
Loading