Skip to content

Commit a92e553

Browse files
committed
fix: fixed problem of music
1 parent 1a2f55a commit a92e553

6 files changed

Lines changed: 51 additions & 45 deletions

File tree

lib/phasetida_flutter.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export 'shell/shell.dart' show PhigrosChartPlayerShellWidget;
77
export 'simulator/simulator.dart' show PhigrosSimulatorRenderWidget;
88

99
const String phasetidaFlutterVersion = "0.3.1";
10-
const String phasetidaCoreVersion = "0.1.14";
10+
const String phasetidaCoreVersion = "0.1.15";
1111

1212
class PhasetidaFlutter {
1313
static Future<void> init() async {

lib/shell/shell_bottom_controller.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class _ShellBottomControllerState extends State<_ShellBottomController> {
4444
} else {
4545
viewModel.paused.value = !viewModel.paused.value;
4646
}
47+
controller.setMusicTime(controller.logTime.value);
4748
state._updateSpeed();
4849
},
4950
icon: ValueListenableBuilder(
@@ -93,6 +94,7 @@ class _ShellBottomControllerState extends State<_ShellBottomController> {
9394
onChangeEnd: (v) {
9495
state._onUserInteraction();
9596
controller.setTime(v);
97+
state._updateSpeed();
9698
_sliding = false;
9799
_slideTime = v;
98100
},

lib/simulator/painter.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ class PainterController {
66
int? logMaxCombo;
77
double? logScore;
88
double? logAccurate;
9-
int? logTapSound;
10-
int? logDragSound;
11-
int? logFlickSound;
129
int? logBufferUsage;
1310

1411
double _startTime = 0;
@@ -41,6 +38,8 @@ class PainterController {
4138
final List<ui.Image> clickImages;
4239
final double offset;
4340

41+
void Function(int, int, int) soundTick;
42+
4443
PainterController({
4544
required this.tapImage,
4645
required this.tapHighlightImage,
@@ -56,6 +55,7 @@ class PainterController {
5655
required this.splashImages,
5756
required this.clickImages,
5857
required this.offset,
58+
required this.soundTick,
5959
});
6060

6161
void setupTime() {
@@ -292,9 +292,7 @@ class _Painter extends CustomPainter {
292292
final tapSound = reader.readUint8();
293293
final dragSound = reader.readUint8();
294294
final flickSound = reader.readUint8();
295-
controller.logTapSound = tapSound;
296-
controller.logDragSound = dragSound;
297-
controller.logFlickSound = flickSound;
295+
controller.soundTick(tapSound, dragSound, flickSound);
298296
}
299297
default:
300298
throw Exception(

lib/simulator/simulator.dart

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ class PhigrosSimulatorRenderController {
4545
ValueNotifier<int> logMaxCombo = ValueNotifier(0);
4646
ValueNotifier<double> logScore = ValueNotifier(0);
4747
ValueNotifier<double> logAccurate = ValueNotifier(0);
48-
ValueNotifier<int> logTapSound = ValueNotifier(0);
49-
ValueNotifier<int> logDragSound = ValueNotifier(0);
50-
ValueNotifier<int> logFlickSound = ValueNotifier(0);
5148
ValueNotifier<int> logBufferUsage = ValueNotifier(0);
5249
ValueNotifier<bool> isLoading = ValueNotifier(true);
5350
ValueNotifier<String?> loadError = ValueNotifier(null);
@@ -61,6 +58,10 @@ class PhigrosSimulatorRenderController {
6158

6259
void setTime(double time) {
6360
_painterController?.setTime(time);
61+
setMusicTime(time);
62+
}
63+
64+
void setMusicTime(double time) {
6465
musicTimeController.add(time);
6566
}
6667

@@ -196,32 +197,39 @@ class _PhigrosSimulatorRenderWidgetState
196197
return;
197198
}
198199
try {
199-
tapSound = await SoLoud.instance.loadAsset(
200+
SoLoud.instance.setMaxActiveVoiceCount(16 * 3 + 2);
201+
final tapSound = await SoLoud.instance.loadAsset(
200202
"packages/phasetida_flutter/assets/sound/hitSong0.wav",
203+
mode: LoadMode.memory,
201204
);
202-
dragSound = await SoLoud.instance.loadAsset(
205+
final dragSound = await SoLoud.instance.loadAsset(
203206
"packages/phasetida_flutter/assets/sound/hitSong1.wav",
207+
mode: LoadMode.memory,
204208
);
205-
flickSound = await SoLoud.instance.loadAsset(
209+
final flickSound = await SoLoud.instance.loadAsset(
206210
"packages/phasetida_flutter/assets/sound/hitSong2.wav",
211+
mode: LoadMode.memory,
207212
);
213+
this.tapSound = tapSound;
214+
this.dragSound = dragSound;
215+
this.flickSound = flickSound;
208216
} catch (e) {
209217
widget.controller.soundError.value = "failed to load effect sound: $e";
210218
}
211219
try {
212220
final songSource = await SoLoud.instance.loadMem(
213221
"song.ogg",
214222
widget.songBuffer,
223+
mode: LoadMode.memory,
215224
);
216225
songLength = SoLoud.instance.getLength(songSource);
217226
musicTotalTime = songLength.inMilliseconds / 1000.0;
218227
final songHandle = await SoLoud.instance.play(
219228
songSource,
220-
paused: false,
229+
paused: true,
221230
looping: true,
222231
loopingStartAt: songLength,
223232
);
224-
SoLoud.instance.setRelativePlaySpeed(songHandle, 0.0000001);
225233
this.songSource = songSource;
226234
this.songHandle = songHandle;
227235
} catch (e) {
@@ -230,7 +238,7 @@ class _PhigrosSimulatorRenderWidgetState
230238
musicTimeSub = widget.controller.musicTimeController.stream.listen((time) {
231239
final songHandle = this.songHandle;
232240
if (songHandle != null && songLength != null) {
233-
final lengthInMillisecond = songLength.inMilliseconds - 10;
241+
final lengthInMillisecond = songLength.inMilliseconds - 5;
234242
SoLoud.instance.setPause(songHandle, false);
235243
SoLoud.instance.seek(
236244
songHandle,
@@ -271,6 +279,13 @@ class _PhigrosSimulatorRenderWidgetState
271279
splashImages: splashImages,
272280
clickImages: clickImages,
273281
offset: offset,
282+
soundTick: (logTapSound, logDragSound, logFlickSound) {
283+
if (widget.controller._enableSound) {
284+
_playSound(tapSound, logTapSound);
285+
_playSound(dragSound, logDragSound);
286+
_playSound(flickSound, logFlickSound);
287+
}
288+
},
274289
);
275290
painterController.setNoteScale(0.25);
276291
painterController.clickScale = 1.5;
@@ -291,21 +306,12 @@ class _PhigrosSimulatorRenderWidgetState
291306
widget.controller.logMaxCombo.value = painterController.logMaxCombo ?? 0;
292307
widget.controller.logScore.value = painterController.logScore ?? 0;
293308
widget.controller.logAccurate.value = painterController.logAccurate ?? 0;
294-
widget.controller.logTapSound.value = painterController.logTapSound ?? 0;
295-
widget.controller.logDragSound.value =
296-
painterController.logDragSound ?? 0;
297-
widget.controller.logFlickSound.value =
298-
painterController.logFlickSound ?? 0;
299309
widget.controller.logBufferUsage.value =
300310
painterController.logBufferUsage ?? 0;
301-
if (widget.controller._enableSound) {
302-
_playSound(tapSound, painterController.logTapSound);
303-
_playSound(dragSound, painterController.logDragSound);
304-
_playSound(flickSound, painterController.logFlickSound);
305-
}
306311
})..start();
307312
painterController.setupTime();
308313
widget.controller.setSpeed(1.0);
314+
widget.controller.setPaused(false);
309315
this.painterController = painterController;
310316
phasetida.resetNoteState(beforeTimeInSecond: 0);
311317
setState(() {

rust/Cargo.lock

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ crate-type = ["cdylib", "staticlib"]
88

99
[dependencies]
1010
flutter_rust_bridge = "=2.11.1"
11-
phasetida-core = { git = "https://github.com/phasetida/phasetida-core.git", tag = "0.1.14" }
11+
phasetida-core = { git = "https://github.com/phasetida/phasetida-core.git", tag = "0.1.15" }
1212
serde = { version = "1.0.228", features = ["derive"] }
1313

1414
[lints.rust]

0 commit comments

Comments
 (0)