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

Music: fix preview plays #58491

Merged
merged 2 commits into from
May 11, 2024
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: 2 additions & 1 deletion apps/src/music/player/MusicPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ export default class MusicPlayer {
effects: soundEvent.effects,
originalBpm: soundData.bpm || DEFAULT_BPM,
pitchShift: this.calculatePitchShift(soundData),
disableTempoAdjustment: soundData.type === 'preview',
},
];
} else if (event.type === 'pattern') {
Expand Down Expand Up @@ -550,7 +551,7 @@ export default class MusicPlayer {
}

private calculatePitchShift(soundData: SoundData) {
if (soundData.type === 'beat') {
if (['beat', 'preview'].includes(soundData.type)) {
return 0;
}
const diff = this.key - (soundData.key || Key.C);
Expand Down
5 changes: 4 additions & 1 deletion apps/src/music/player/ToneJSPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ class ToneJSPlayer implements AudioPlayer {
return;
}

const playbackRate = Transport.bpm.value / sample.originalBpm;
const playbackRate = sample.disableTempoAdjustment
? 1
: Transport.bpm.value / sample.originalBpm;

const player = this.createPlayer(
buffer,
playbackRate,
Expand Down
2 changes: 2 additions & 0 deletions apps/src/music/player/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ export interface SampleEvent {
effects?: Effects;
// Length in measures to play the sample for
length?: number;
// Whether tempo should not be adjusted.
disableTempoAdjustment?: boolean;
}

/** A sequence of notes played on a sampler instrument */
Expand Down