Minor simplification
This commit is contained in:
parent
2cc1f230f4
commit
d217017796
1 changed files with 3 additions and 7 deletions
|
|
@ -7,11 +7,6 @@ class MidiSequence(val resolution: Int = 60) {
|
||||||
val out: MutableList<Byte> = mutableListOf<Byte>()
|
val out: MutableList<Byte> = mutableListOf<Byte>()
|
||||||
private var lastTick = 0L
|
private var lastTick = 0L
|
||||||
|
|
||||||
fun getDeltaAndSync(channel: Int, currentTick: Long): Long {
|
|
||||||
val delta = currentTick - lastTick
|
|
||||||
lastTick = currentTick
|
|
||||||
return delta
|
|
||||||
}
|
|
||||||
fun createTrack(): MutableList<Byte> {
|
fun createTrack(): MutableList<Byte> {
|
||||||
val newTrack = mutableListOf<Byte>()
|
val newTrack = mutableListOf<Byte>()
|
||||||
tracks.add(newTrack)
|
tracks.add(newTrack)
|
||||||
|
|
@ -45,7 +40,8 @@ class MidiSequence(val resolution: Int = 60) {
|
||||||
}
|
}
|
||||||
fun MutableList<Byte>.addNote(channel: Int, pitch: Int, currentTick: Long, type: Int = 80, finalVelocity: Int = 100) {
|
fun MutableList<Byte>.addNote(channel: Int, pitch: Int, currentTick: Long, type: Int = 80, finalVelocity: Int = 100) {
|
||||||
// Calcul du Delta-Time
|
// Calcul du Delta-Time
|
||||||
val delta = getDeltaAndSync(channel, currentTick)
|
val delta = currentTick - lastTick
|
||||||
|
lastTick = currentTick
|
||||||
|
|
||||||
val status = if (type == 80) (0x80 or channel) else (0x90 or channel)
|
val status = if (type == 80) (0x80 or channel) else (0x90 or channel)
|
||||||
|
|
||||||
|
|
@ -83,7 +79,7 @@ class MidiSequence(val resolution: Int = 60) {
|
||||||
out.write16Bit(1)
|
out.write16Bit(1)
|
||||||
|
|
||||||
// 4. Nombre de pistes (16 bits)
|
// 4. Nombre de pistes (16 bits)
|
||||||
out.write16Bit(trackCount)
|
out.write16Bit(trackCount)
|
||||||
|
|
||||||
// 5. Division / Résolution (16 bits)
|
// 5. Division / Résolution (16 bits)
|
||||||
// Ticks par noire (votre variable 'resolution')
|
// Ticks par noire (votre variable 'resolution')
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue