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
3 changes: 0 additions & 3 deletions src.compiler/csharp/CSharpAstPrinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,6 @@ export default class CSharpAstPrinter {
}

private writeType(type: cs.TypeNode, forNew: boolean = false, asNativeArray: boolean = false, forTypeConstraint: boolean = false) {
if (!type) {
console.log('ERR');
}
switch (type.nodeType) {
case cs.SyntaxKind.PrimitiveTypeNode:
if (forTypeConstraint) {
Expand Down
6 changes: 5 additions & 1 deletion src.compiler/csharp/CSharpAstTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,11 @@ export default class CSharpAstTransformer {
parent: parent
} as cs.UnresolvedTypeNode;

const typeArguments = (tsType as ts.TypeReference)?.typeArguments;
let typeArguments = (tsType as ts.TypeReference)?.typeArguments;
if(tsType && !typeArguments) {
const nonNullable = this._context.typeChecker.getNonNullableType(tsType);
typeArguments = (nonNullable as ts.TypeReference)?.typeArguments;
}
if (typeArguments) {
unresolved.typeArguments = typeArguments.map(a => this.createUnresolvedTypeNode(parent, tsNode, a));
}
Expand Down
6 changes: 3 additions & 3 deletions src.compiler/csharp/CSharpEmitterContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export default class CSharpEmitterContext {
return csType;
}

csType = this.resolveUnionType(node, tsType);
csType = this.resolveUnionType(node, tsType, typeArguments);
if (csType) {
return csType;
}
Expand Down Expand Up @@ -493,7 +493,7 @@ export default class CSharpEmitterContext {
}
}

private resolveUnionType(parent: cs.Node, tsType: ts.Type): cs.TypeNode | null {
private resolveUnionType(parent: cs.Node, tsType: ts.Type, typeArguments?: cs.UnresolvedTypeNode[]): cs.TypeNode | null {
if (!tsType.isUnion()) {
return null;
}
Expand Down Expand Up @@ -562,7 +562,7 @@ export default class CSharpEmitterContext {
if (!actualType) {
return null;
}
const type = this.getTypeFromTsType(parent, actualType);
const type = this.getTypeFromTsType(parent, actualType, undefined, typeArguments);
return {
nodeType: cs.SyntaxKind.TypeReference,
parent: parent,
Expand Down
2 changes: 1 addition & 1 deletion src.csharp/AlphaTab/AlphaTab.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>AlphaTab</RootNamespace>
Expand Down
10 changes: 10 additions & 0 deletions src.csharp/AlphaTab/Core/EcmaScript/Iterable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace AlphaTab.Core.EcmaScript
{
public interface Iterable<T> : IEnumerable<T>
{
}
}
14 changes: 12 additions & 2 deletions src.csharp/AlphaTab/Core/EcmaScript/Set.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
Expand All @@ -7,7 +7,17 @@ namespace AlphaTab.Core.EcmaScript
{
public class Set<T> : IEnumerable<T>
{
private readonly HashSet<T> _data = new HashSet<T>();
private readonly HashSet<T> _data;

public Set()
{
_data = new HashSet<T>();
}

public Set(IEnumerable<T> values)
{
_data = new HashSet<T>(values);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add(T item)
Expand Down
25 changes: 15 additions & 10 deletions src.csharp/AlphaTab/Core/EcmaScript/Uint8Array.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -16,6 +16,11 @@ public class Uint8Array : IEnumerable<byte>, IEnumerable<double>

public ArraySegment<byte> Data => _data;

public Uint8Array(IList<double> data)
{
_data = new ArraySegment<byte>(data.Select(d => (byte)d).ToArray());
}

public Uint8Array(byte[] data)
{
_data = new ArraySegment<byte>(data);
Expand All @@ -27,34 +32,34 @@ private Uint8Array(ArraySegment<byte> data)
}

public Uint8Array(double size)
: this(new byte[(int) size])
: this(new byte[(int)size])
{
}

public Uint8Array(IEnumerable<int> values)
: this(values.Select(d => (byte) d).ToArray())
: this(values.Select(d => (byte)d).ToArray())
{
}

public double this[double index]
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _data.Array[_data.Offset + (int) index];
get => _data.Array[_data.Offset + (int)index];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set => _data.Array[_data.Offset + (int) index] = (byte) value;
set => _data.Array[_data.Offset + (int)index] = (byte)value;
}

public Uint8Array Subarray(double begin, double end)
{
return new Uint8Array(new ArraySegment<byte>(_data.Array, _data.Offset + (int) begin,
(int) (end - begin)));
return new Uint8Array(new ArraySegment<byte>(_data.Array, _data.Offset + (int)begin,
(int)(end - begin)));
}

public void Set(Uint8Array subarray, double pos)
{
var buffer = subarray.Buffer.Raw;
System.Buffer.BlockCopy(buffer.Array, (int) buffer.Offset, _data.Array,
_data.Offset + (int) pos, buffer.Count);
System.Buffer.BlockCopy(buffer.Array, (int)buffer.Offset, _data.Array,
_data.Offset + (int)pos, buffer.Count);
}

public static implicit operator Uint8Array(byte[] v)
Expand All @@ -64,7 +69,7 @@ public static implicit operator Uint8Array(byte[] v)

IEnumerator<double> IEnumerable<double>.GetEnumerator()
{
return _data.Select(d => (double) d).GetEnumerator();
return _data.Select(d => (double)d).GetEnumerator();
}

public IEnumerator<byte> GetEnumerator()
Expand Down
17 changes: 16 additions & 1 deletion src.csharp/AlphaTab/Platform/CSharp/AlphaSynthWorkerApiBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System;
using System.Collections.Generic;
using AlphaTab.Core.EcmaScript;
using AlphaTab.Midi;
using AlphaTab.Synth;
Expand Down Expand Up @@ -34,6 +35,7 @@ protected void Initialize()
Player.MidiLoaded.On(OnMidiLoaded);
Player.MidiLoadFailed.On(OnMidiLoadFailed);
Player.ReadyForPlayback.On(OnReadyForPlayback);
Player.MidiEventsPlayed.On(OnMidiEventsPlayed);

DispatchOnUiThread(OnReady);
}
Expand Down Expand Up @@ -65,6 +67,12 @@ public double CountInVolume
set => DispatchOnWorkerThread(() => { Player.CountInVolume = value; });
}

public IList<MidiEventType> MidiEventsPlayedFilter
{
get => Player.MidiEventsPlayedFilter;
set => DispatchOnWorkerThread(() => { Player.MidiEventsPlayedFilter = value; });
}

public double MetronomeVolume
{
get => Player.MetronomeVolume;
Expand Down Expand Up @@ -172,10 +180,12 @@ public void SetChannelVolume(double channel, double volume)
public IEventEmitter Finished { get; } = new EventEmitter();
public IEventEmitter SoundFontLoaded { get; } = new EventEmitter();
public IEventEmitterOfT<Error> SoundFontLoadFailed { get; } =new EventEmitterOfT<Error>();
public IEventEmitterOfT<MidiFile> MidiLoad { get; } = new EventEmitterOfT<MidiFile>();
public IEventEmitterOfT<PositionChangedEventArgs> MidiLoaded { get; } = new EventEmitterOfT<PositionChangedEventArgs>();
public IEventEmitterOfT<Error> MidiLoadFailed { get; } = new EventEmitterOfT<Error>();
public IEventEmitterOfT<PlayerStateChangedEventArgs> StateChanged { get; } = new EventEmitterOfT<PlayerStateChangedEventArgs>();
public IEventEmitterOfT<PositionChangedEventArgs> PositionChanged { get; } = new EventEmitterOfT<PositionChangedEventArgs>();
public IEventEmitterOfT<MidiEventsPlayedEventArgs> MidiEventsPlayed { get; } = new EventEmitterOfT<MidiEventsPlayedEventArgs>();

protected virtual void OnReady()
{
Expand Down Expand Up @@ -212,6 +222,11 @@ protected virtual void OnMidiLoadFailed(Error e)
DispatchOnUiThread(() => ((EventEmitterOfT<Error>)MidiLoadFailed).Trigger(e));
}

protected virtual void OnMidiEventsPlayed(MidiEventsPlayedEventArgs e)
{
DispatchOnUiThread(() => ((EventEmitterOfT<MidiEventsPlayedEventArgs>)MidiEventsPlayed).Trigger(e));
}

protected virtual void OnStateChanged(PlayerStateChangedEventArgs obj)
{
DispatchOnUiThread(() => ((EventEmitterOfT<PlayerStateChangedEventArgs>)StateChanged).Trigger(obj));
Expand Down
31 changes: 31 additions & 0 deletions src/AlphaTabApiBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import { Logger } from '@src/Logger';
import { ModelUtils } from '@src/model/ModelUtils';
import { AlphaTabError, AlphaTabErrorType } from '@src/AlphaTabError';
import { Note } from './model/Note';
import { MidiEventType } from './midi/MidiEvent';
import { MidiEventsPlayedEventArgs } from './synth/MidiEventsPlayedEventArgs';

class SelectionInfo {
public beat: Beat;
Expand Down Expand Up @@ -435,6 +437,19 @@ export class AlphaTabApiBase<TSettings> {
}
}

public get midiEventsPlayedFilter(): MidiEventType[] {
if (!this.player) {
return [];
}
return this.player.midiEventsPlayedFilter;
}

public set midiEventsPlayedFilter(value: MidiEventType[]) {
if (this.player) {
this.player.midiEventsPlayedFilter = value;
}
}

public get tickPosition(): number {
if (!this.player) {
return 0;
Expand Down Expand Up @@ -543,6 +558,7 @@ export class AlphaTabApiBase<TSettings> {
});
this.player.stateChanged.on(this.onPlayerStateChanged.bind(this));
this.player.positionChanged.on(this.onPlayerPositionChanged.bind(this));
this.player.midiEventsPlayed.on(this.onMidiEventsPlayed.bind(this));
this.player.finished.on(this.onPlayerFinished.bind(this));
if (this.settings.player.enableCursor) {
this.setupCursors();
Expand All @@ -561,6 +577,7 @@ export class AlphaTabApiBase<TSettings> {
let generator: MidiFileGenerator = new MidiFileGenerator(this.score, this.settings, handler);
generator.generate();
this._tickCache = generator.tickLookup;
this.onMidiLoad(midiFile);
this.player.loadMidiFile(midiFile);
}

Expand Down Expand Up @@ -1221,6 +1238,12 @@ export class AlphaTabApiBase<TSettings> {
this.uiFacade.triggerEvent(this.container, 'soundFontLoaded', null);
}

public midiLoad: IEventEmitterOfT<MidiFile> = new EventEmitterOfT<MidiFile>();
private onMidiLoad(e:MidiFile): void {
(this.midiLoad as EventEmitterOfT<MidiFile>).trigger(e);
this.uiFacade.triggerEvent(this.container, 'midiLoad', e);
}

public midiLoaded: IEventEmitterOfT<PositionChangedEventArgs> = new EventEmitterOfT<PositionChangedEventArgs>();
private onMidiLoaded(e:PositionChangedEventArgs): void {
(this.midiLoaded as EventEmitterOfT<PositionChangedEventArgs>).trigger(e);
Expand All @@ -1242,4 +1265,12 @@ export class AlphaTabApiBase<TSettings> {
(this.playerPositionChanged as EventEmitterOfT<PositionChangedEventArgs>).trigger(e);
this.uiFacade.triggerEvent(this.container, 'playerPositionChanged', e);
}

public midiEventsPlayed: IEventEmitterOfT<MidiEventsPlayedEventArgs> = new EventEmitterOfT<
MidiEventsPlayedEventArgs
>();
private onMidiEventsPlayed(e: MidiEventsPlayedEventArgs): void {
(this.midiEventsPlayed as EventEmitterOfT<MidiEventsPlayedEventArgs>).trigger(e);
this.uiFacade.triggerEvent(this.container, 'midiEventsPlayed', e);
}
}
2 changes: 2 additions & 0 deletions src/alphatab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import { MetaDataEvent } from '@src/midi/MetaDataEvent';
import { MetaEvent, MetaEventType } from '@src/midi/MetaEvent';
import { MetaNumberEvent } from '@src/midi/MetaNumberEvent';
import { MidiEvent, MidiEventType } from '@src/midi/MidiEvent';
import { Midi20PerNotePitchBendEvent } from '@src/midi/Midi20PerNotePitchBendEvent';
import { SystemCommonEvent, SystemCommonType } from '@src/midi/SystemCommonEvent';
import { SystemExclusiveEvent } from '@src/midi/SystemExclusiveEvent';
import { MidiFileGenerator } from '@src/midi/MidiFileGenerator';
Expand All @@ -89,6 +90,7 @@ export const midi = {
MetaNumberEvent,
MidiEvent,
MidiEventType,
Midi20PerNotePitchBendEvent,
SystemCommonEvent,
SystemCommonType,
SystemExclusiveEvent,
Expand Down
8 changes: 8 additions & 0 deletions src/io/IOHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ export class IOHelper {
return (ch4 << 24) | (ch3 << 16) | (ch2 << 8) | ch1;
}

public static decodeUInt32LE(data: Uint8Array, index: number): number {
let ch1: number = data[index];
let ch2: number = data[index + 1];
let ch3: number = data[index + 2];
let ch4: number = data[index + 3];
return (ch4 << 24) | (ch3 << 16) | (ch2 << 8) | ch1;
}

public static readUInt16LE(input: IReadable): number {
let ch1: number = input.readByte();
let ch2: number = input.readByte();
Expand Down
Loading