Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a count-in option #432

Merged
merged 4 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Final corretions on count-in
  • Loading branch information
Danielku15 committed Nov 27, 2020
commit dc7d9c7a95d7ba474408520c250baa1e42cc66ee
3 changes: 3 additions & 0 deletions playground-template/control-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@
</div>

<div class="at-player-right">
<a href="#" class="at-count-in disabled" data-toggle="tooltip" data-placement="top" title="Count-In">
<i class="fas fa-hourglass-half"></i>
</a>
<a href="#" class="at-metronome disabled" data-toggle="tooltip" data-placement="top" title="Metronome">
<i class="fas fa-edit"></i>
</a>
Expand Down
11 changes: 11 additions & 0 deletions playground-template/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,17 @@ function setupControl(selector) {
}
};

control.querySelector('.at-count-in').onclick = function (e) {
e.stopPropagation();
const link = e.target.closest('a');
link.classList.toggle('active');
if (link.classList.contains('active')) {
at.countInVolume = 1;
} else {
at.countInVolume = 0;
}
};

control.querySelectorAll('.at-speed-options a').forEach(function (a) {
a.onclick = function (e) {
e.preventDefault();
Expand Down
13 changes: 13 additions & 0 deletions src/AlphaTabApiBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,19 @@ export class AlphaTabApiBase<TSettings> {
}
}

public get countInVolume(): number {
if (!this.player) {
return 0;
}
return this.player.countInVolume;
}

public set countInVolume(value: number) {
if (this.player) {
this.player.countInVolume = value;
}
}

public get tickPosition(): number {
if (!this.player) {
return 0;
Expand Down
7 changes: 4 additions & 3 deletions src/synth/AlphaSynth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,14 @@ export class AlphaSynth implements IAlphaSynth {
return false;
}
this.output.activate();

this.playInternal();

if (this._countInVolume > 0) {
Logger.debug('AlphaSynth', 'Starting countin');
this._sequencer.startCountIn();
this._synthesizer.setupMetronomeChannel(this._countInVolume);
this.tickPosition = 0;
} else {
this.playInternal();
}

this.output.play();
Expand Down Expand Up @@ -355,8 +356,8 @@ export class AlphaSynth implements IAlphaSynth {
if (this._tickPosition >= endTick) {
Logger.debug('AlphaSynth', 'Finished playback');
if (this._sequencer.isPlayingCountIn) {
this.tickPosition = 0;
this._sequencer.resetCountIn();
this.timePosition = this._sequencer.currentTime;
this.playInternal()
} else if (this._sequencer.isPlayingOneTimeMidi) {
this._sequencer.resetOneTimeMidi();
Expand Down
12 changes: 6 additions & 6 deletions src/synth/MidiFileSequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export class MidiFileSequencer {

public isLooping: boolean = false;

public get currentTime() {
return this._currentState.currentTime;
}

/**
* Gets the duration of the song in ticks.
*/
Expand Down Expand Up @@ -105,12 +109,6 @@ export class MidiFileSequencer {
}
}

// move back some ticks to ensure the on-time events are played
timePosition -= 25;
if (timePosition < 0) {
timePosition = 0;
}

if (timePosition > this._currentState.currentTime) {
this.silentProcess(timePosition - this._currentState.currentTime);
} else if (timePosition < this._currentState.currentTime) {
Expand Down Expand Up @@ -139,6 +137,8 @@ export class MidiFileSequencer {
}
}

this._currentState.currentTime = finalTime;

let duration: number = Date.now() - start;
Logger.debug('Sequencer', 'Silent seek finished in ' + duration + 'ms');
}
Expand Down