This repository has been archived by the owner on Apr 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
105 changed files
with
1,932 additions
and
1,878 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ on: | |
- master | ||
|
||
env: | ||
flutter_version: "1.22.5" | ||
flutter_version: "1.22.6" | ||
|
||
jobs: | ||
buildApk: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="AndroidDev" type="FlutterRunConfigurationType" factoryName="Flutter"> | ||
<option name="additionalArgs" value="--flavor=dev" /> | ||
<option name="buildFlavor" value="dev" /> | ||
<option name="filePath" value="$PROJECT_DIR$/lib/main.dart" /> | ||
<method v="2" /> | ||
</configuration> | ||
</component> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="IosDev" type="FlutterRunConfigurationType" factoryName="Flutter"> | ||
<option name="filePath" value="$PROJECT_DIR$/lib/main.dart" /> | ||
<method v="2" /> | ||
</configuration> | ||
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="instrument_checker.dart" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application" nameIsGenerated="true"> | ||
<option name="filePath" value="$PROJECT_DIR$/lib/instrument_checker.dart" /> | ||
<option name="workingDirectory" value="$PROJECT_DIR$" /> | ||
<method v="2" /> | ||
</configuration> | ||
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
android/app/src/main/kotlin/com/chaomao/hitnotes/SoundMethodCallHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.chaomao.hitnotes | ||
|
||
import android.media.AudioAttributes | ||
import android.media.AudioManager | ||
import android.media.SoundPool | ||
import android.os.Build | ||
import io.flutter.plugin.common.MethodCall | ||
import io.flutter.plugin.common.MethodChannel | ||
import kotlin.math.pow | ||
|
||
class SoundMethodCallHandler : MethodChannel.MethodCallHandler { | ||
private lateinit var soundPool: SoundPool | ||
private var loadedCount = 0 | ||
private var soundIds = mapOf<Int, Int>() | ||
private var rates = mapOf<Int, Float>() | ||
private var activeSounds = arrayListOf<Int>() | ||
private val maxStreams = 8 | ||
|
||
override fun onMethodCall(methodCall: MethodCall, result: MethodChannel.Result) { | ||
when (methodCall.method) { | ||
"load" -> { | ||
val arguments = methodCall.arguments as Map<String, Any> | ||
val soundPaths = arguments["soundPaths"] as Map<Int, String> | ||
val baseNotes = arguments["baseNotes"] as Map<Int, Int> | ||
soundPool = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
SoundPool.Builder() | ||
.setMaxStreams(maxStreams) | ||
.setAudioAttributes(AudioAttributes.Builder().setLegacyStreamType | ||
(AudioManager.STREAM_MUSIC) | ||
.setUsage(AudioAttributes.USAGE_GAME) | ||
.build()) | ||
.build() | ||
} else { | ||
SoundPool(maxStreams, AudioManager.STREAM_MUSIC, 1) | ||
}.apply { | ||
setOnLoadCompleteListener { _, _, _ -> | ||
loadedCount++ | ||
if (loadedCount == soundPaths.size) { | ||
result.success(null) | ||
} | ||
} | ||
} | ||
val ids = hashMapOf<Int, Int>() | ||
for ((baseNote, path) in soundPaths) { | ||
val soundId = soundPool.load(path, 1) | ||
ids[baseNote] = soundId | ||
} | ||
rates = baseNotes.mapValues { 2f.pow((it.key - it.value).toFloat() / 12f) } | ||
this.soundIds = baseNotes.mapValues { ids[it.value]!! } | ||
} | ||
"play" -> { | ||
val arguments = methodCall.arguments as Map<String, Any> | ||
val note = arguments["note"] as Int | ||
val streamId = soundPool.play(soundIds[note]!!, 1.0f, 1.0f, 0, | ||
0, rates[note]!!) | ||
activeSounds.add(streamId) | ||
if (activeSounds.size > maxStreams) { | ||
val firstSound = activeSounds.first() | ||
soundPool.stop(firstSound) | ||
activeSounds.remove(firstSound) | ||
} | ||
result.success(null) | ||
} | ||
"release" -> { | ||
if (this::soundPool.isInitialized) { | ||
soundPool.release() | ||
} | ||
loadedCount = 0 | ||
activeSounds.clear() | ||
result.success(null) | ||
} | ||
else -> { | ||
result.notImplemented() | ||
} | ||
} | ||
} | ||
} |
97 changes: 0 additions & 97 deletions
97
android/app/src/main/kotlin/com/chaomao/hitnotes/SoundPlayerPlugin.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.