diff --git a/.idea/misc.xml b/.idea/misc.xml
index c668cf4..5c9d3cd 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -12,7 +12,7 @@
-
+
diff --git a/.idea/misc.xml b/.idea/misc.xml
index c668cf4..5c9d3cd 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -12,7 +12,7 @@
-
+
diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt
index 0b075f1..8f4fbe7 100644
--- a/app/src/main/java/com/lukas/music/MainActivity.kt
+++ b/app/src/main/java/com/lukas/music/MainActivity.kt
@@ -3,7 +3,6 @@
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.lukas.music.databinding.ActivityMainBinding
-import com.lukas.music.instruments.Rhythm
import com.lukas.music.ui.fragments.CreditsFragment
import com.lukas.music.ui.fragments.InstrumentListFragment
import com.lukas.music.ui.fragments.PlayFragment
@@ -30,7 +29,6 @@
binding.tabPager.registerOnPageChangeCallback(PageListener(binding.tabLayout))
binding.tabLayout.addOnTabSelectedListener(TabListener(binding.tabPager))
startAudio()
- Rhythm.start()
supportActionBar?.hide()
}
diff --git a/.idea/misc.xml b/.idea/misc.xml
index c668cf4..5c9d3cd 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -12,7 +12,7 @@
-
+
diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt
index 0b075f1..8f4fbe7 100644
--- a/app/src/main/java/com/lukas/music/MainActivity.kt
+++ b/app/src/main/java/com/lukas/music/MainActivity.kt
@@ -3,7 +3,6 @@
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.lukas.music.databinding.ActivityMainBinding
-import com.lukas.music.instruments.Rhythm
import com.lukas.music.ui.fragments.CreditsFragment
import com.lukas.music.ui.fragments.InstrumentListFragment
import com.lukas.music.ui.fragments.PlayFragment
@@ -30,7 +29,6 @@
binding.tabPager.registerOnPageChangeCallback(PageListener(binding.tabLayout))
binding.tabLayout.addOnTabSelectedListener(TabListener(binding.tabPager))
startAudio()
- Rhythm.start()
supportActionBar?.hide()
}
diff --git a/app/src/main/java/com/lukas/music/instruments/Rhythm.kt b/app/src/main/java/com/lukas/music/instruments/Rhythm.kt
index c449d04..4b47c80 100644
--- a/app/src/main/java/com/lukas/music/instruments/Rhythm.kt
+++ b/app/src/main/java/com/lukas/music/instruments/Rhythm.kt
@@ -13,11 +13,19 @@
}
}
- fun start() {
- Timer().schedule(0, 500) {
- if (on) {
- Song.currentSong.step()
- }
+ private val callback: TimerTask.() -> Unit = {
+ if (on) {
+ Song.currentSong.step()
}
}
+
+ private val timer = Timer()
+ private lateinit var task: TimerTask
+
+ fun setTempo(tempo: Int) {
+ if (this::task.isInitialized) {
+ task.cancel()
+ }
+ task = timer.schedule((60000 / tempo).toLong(), (60000 / tempo).toLong(), callback)
+ }
}
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index c668cf4..5c9d3cd 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -12,7 +12,7 @@
-
+
diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt
index 0b075f1..8f4fbe7 100644
--- a/app/src/main/java/com/lukas/music/MainActivity.kt
+++ b/app/src/main/java/com/lukas/music/MainActivity.kt
@@ -3,7 +3,6 @@
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.lukas.music.databinding.ActivityMainBinding
-import com.lukas.music.instruments.Rhythm
import com.lukas.music.ui.fragments.CreditsFragment
import com.lukas.music.ui.fragments.InstrumentListFragment
import com.lukas.music.ui.fragments.PlayFragment
@@ -30,7 +29,6 @@
binding.tabPager.registerOnPageChangeCallback(PageListener(binding.tabLayout))
binding.tabLayout.addOnTabSelectedListener(TabListener(binding.tabPager))
startAudio()
- Rhythm.start()
supportActionBar?.hide()
}
diff --git a/app/src/main/java/com/lukas/music/instruments/Rhythm.kt b/app/src/main/java/com/lukas/music/instruments/Rhythm.kt
index c449d04..4b47c80 100644
--- a/app/src/main/java/com/lukas/music/instruments/Rhythm.kt
+++ b/app/src/main/java/com/lukas/music/instruments/Rhythm.kt
@@ -13,11 +13,19 @@
}
}
- fun start() {
- Timer().schedule(0, 500) {
- if (on) {
- Song.currentSong.step()
- }
+ private val callback: TimerTask.() -> Unit = {
+ if (on) {
+ Song.currentSong.step()
}
}
+
+ private val timer = Timer()
+ private lateinit var task: TimerTask
+
+ fun setTempo(tempo: Int) {
+ if (this::task.isInitialized) {
+ task.cancel()
+ }
+ task = timer.schedule((60000 / tempo).toLong(), (60000 / tempo).toLong(), callback)
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt
index b7e6d73..a2eaf90 100644
--- a/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt
+++ b/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt
@@ -31,25 +31,14 @@
if (Rhythm.on) android.R.drawable.ic_media_pause else android.R.drawable.ic_media_play
)
}
- binding.masterVolumeSlider.min = 0
- binding.masterVolumeSlider.max = 100
- binding.masterVolumeSlider.setOnSeekBarChangeListener(object :
- SeekBar.OnSeekBarChangeListener {
- override fun onProgressChanged(
- seekBar: SeekBar,
- progress: Int, fromUser: Boolean
- ) {
- setMasterVolume(progress.toDouble() / 100.0)
- binding.masterVolumeText.text = "Master volume: $progress%"
- }
-
- override fun onStartTrackingTouch(seekBar: SeekBar) {
- }
-
- override fun onStopTrackingTouch(seekBar: SeekBar) {
- }
- })
- binding.masterVolumeSlider.progress = 100
+ setupSlider(binding.masterVolumeSlider, 0, 100, 100) {
+ setMasterVolume(it.toDouble() / 100.0)
+ binding.masterVolumeText.text = "Master volume: $it%"
+ }
+ setupSlider(binding.tempoSlider, 50, 150, 90) {
+ Rhythm.setTempo(it)
+ binding.tempoText.text = "tempo: ${it}bpm"
+ }
val layout = RadioGroup.LayoutParams(
RadioGroup.LayoutParams.WRAP_CONTENT,
RadioGroup.LayoutParams.MATCH_PARENT
@@ -104,6 +93,33 @@
return binding.root
}
+ private fun setupSlider(
+ slider: SeekBar,
+ min: Int,
+ max: Int,
+ initialProgress: Int,
+ callback: (Int) -> Unit
+ ) {
+ slider.min = min
+ slider.max = max
+ slider.setOnSeekBarChangeListener(object :
+ SeekBar.OnSeekBarChangeListener {
+ override fun onProgressChanged(
+ seekBar: SeekBar,
+ progress: Int, fromUser: Boolean
+ ) {
+ callback(progress)
+ }
+
+ override fun onStartTrackingTouch(seekBar: SeekBar) {
+ }
+
+ override fun onStopTrackingTouch(seekBar: SeekBar) {
+ }
+ })
+ slider.progress = initialProgress
+ }
+
private fun putChords() {
binding.phraseDisplay.removeAllViews()
chordDisplays.clear()
diff --git a/.idea/misc.xml b/.idea/misc.xml
index c668cf4..5c9d3cd 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -12,7 +12,7 @@
-
+
diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt
index 0b075f1..8f4fbe7 100644
--- a/app/src/main/java/com/lukas/music/MainActivity.kt
+++ b/app/src/main/java/com/lukas/music/MainActivity.kt
@@ -3,7 +3,6 @@
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.lukas.music.databinding.ActivityMainBinding
-import com.lukas.music.instruments.Rhythm
import com.lukas.music.ui.fragments.CreditsFragment
import com.lukas.music.ui.fragments.InstrumentListFragment
import com.lukas.music.ui.fragments.PlayFragment
@@ -30,7 +29,6 @@
binding.tabPager.registerOnPageChangeCallback(PageListener(binding.tabLayout))
binding.tabLayout.addOnTabSelectedListener(TabListener(binding.tabPager))
startAudio()
- Rhythm.start()
supportActionBar?.hide()
}
diff --git a/app/src/main/java/com/lukas/music/instruments/Rhythm.kt b/app/src/main/java/com/lukas/music/instruments/Rhythm.kt
index c449d04..4b47c80 100644
--- a/app/src/main/java/com/lukas/music/instruments/Rhythm.kt
+++ b/app/src/main/java/com/lukas/music/instruments/Rhythm.kt
@@ -13,11 +13,19 @@
}
}
- fun start() {
- Timer().schedule(0, 500) {
- if (on) {
- Song.currentSong.step()
- }
+ private val callback: TimerTask.() -> Unit = {
+ if (on) {
+ Song.currentSong.step()
}
}
+
+ private val timer = Timer()
+ private lateinit var task: TimerTask
+
+ fun setTempo(tempo: Int) {
+ if (this::task.isInitialized) {
+ task.cancel()
+ }
+ task = timer.schedule((60000 / tempo).toLong(), (60000 / tempo).toLong(), callback)
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt
index b7e6d73..a2eaf90 100644
--- a/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt
+++ b/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt
@@ -31,25 +31,14 @@
if (Rhythm.on) android.R.drawable.ic_media_pause else android.R.drawable.ic_media_play
)
}
- binding.masterVolumeSlider.min = 0
- binding.masterVolumeSlider.max = 100
- binding.masterVolumeSlider.setOnSeekBarChangeListener(object :
- SeekBar.OnSeekBarChangeListener {
- override fun onProgressChanged(
- seekBar: SeekBar,
- progress: Int, fromUser: Boolean
- ) {
- setMasterVolume(progress.toDouble() / 100.0)
- binding.masterVolumeText.text = "Master volume: $progress%"
- }
-
- override fun onStartTrackingTouch(seekBar: SeekBar) {
- }
-
- override fun onStopTrackingTouch(seekBar: SeekBar) {
- }
- })
- binding.masterVolumeSlider.progress = 100
+ setupSlider(binding.masterVolumeSlider, 0, 100, 100) {
+ setMasterVolume(it.toDouble() / 100.0)
+ binding.masterVolumeText.text = "Master volume: $it%"
+ }
+ setupSlider(binding.tempoSlider, 50, 150, 90) {
+ Rhythm.setTempo(it)
+ binding.tempoText.text = "tempo: ${it}bpm"
+ }
val layout = RadioGroup.LayoutParams(
RadioGroup.LayoutParams.WRAP_CONTENT,
RadioGroup.LayoutParams.MATCH_PARENT
@@ -104,6 +93,33 @@
return binding.root
}
+ private fun setupSlider(
+ slider: SeekBar,
+ min: Int,
+ max: Int,
+ initialProgress: Int,
+ callback: (Int) -> Unit
+ ) {
+ slider.min = min
+ slider.max = max
+ slider.setOnSeekBarChangeListener(object :
+ SeekBar.OnSeekBarChangeListener {
+ override fun onProgressChanged(
+ seekBar: SeekBar,
+ progress: Int, fromUser: Boolean
+ ) {
+ callback(progress)
+ }
+
+ override fun onStartTrackingTouch(seekBar: SeekBar) {
+ }
+
+ override fun onStopTrackingTouch(seekBar: SeekBar) {
+ }
+ })
+ slider.progress = initialProgress
+ }
+
private fun putChords() {
binding.phraseDisplay.removeAllViews()
chordDisplays.clear()
diff --git a/app/src/main/java/com/lukas/music/util/Cycle.kt b/app/src/main/java/com/lukas/music/util/Cycle.kt
index f1ef055..4bf3ec5 100644
--- a/app/src/main/java/com/lukas/music/util/Cycle.kt
+++ b/app/src/main/java/com/lukas/music/util/Cycle.kt
@@ -44,12 +44,10 @@
if (size == 0) {
return null
}
- val callback: () -> Unit = {
+ this[index].step()
+ if (this[index].index == 0) {
super.step()
}
- this[index].wraparoundListeners += callback
- this[index].step()
- this[index].wraparoundListeners -= callback
for (callback in miniStepCallback) {
callback()
}
diff --git a/.idea/misc.xml b/.idea/misc.xml
index c668cf4..5c9d3cd 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -12,7 +12,7 @@
-
+
diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt
index 0b075f1..8f4fbe7 100644
--- a/app/src/main/java/com/lukas/music/MainActivity.kt
+++ b/app/src/main/java/com/lukas/music/MainActivity.kt
@@ -3,7 +3,6 @@
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.lukas.music.databinding.ActivityMainBinding
-import com.lukas.music.instruments.Rhythm
import com.lukas.music.ui.fragments.CreditsFragment
import com.lukas.music.ui.fragments.InstrumentListFragment
import com.lukas.music.ui.fragments.PlayFragment
@@ -30,7 +29,6 @@
binding.tabPager.registerOnPageChangeCallback(PageListener(binding.tabLayout))
binding.tabLayout.addOnTabSelectedListener(TabListener(binding.tabPager))
startAudio()
- Rhythm.start()
supportActionBar?.hide()
}
diff --git a/app/src/main/java/com/lukas/music/instruments/Rhythm.kt b/app/src/main/java/com/lukas/music/instruments/Rhythm.kt
index c449d04..4b47c80 100644
--- a/app/src/main/java/com/lukas/music/instruments/Rhythm.kt
+++ b/app/src/main/java/com/lukas/music/instruments/Rhythm.kt
@@ -13,11 +13,19 @@
}
}
- fun start() {
- Timer().schedule(0, 500) {
- if (on) {
- Song.currentSong.step()
- }
+ private val callback: TimerTask.() -> Unit = {
+ if (on) {
+ Song.currentSong.step()
}
}
+
+ private val timer = Timer()
+ private lateinit var task: TimerTask
+
+ fun setTempo(tempo: Int) {
+ if (this::task.isInitialized) {
+ task.cancel()
+ }
+ task = timer.schedule((60000 / tempo).toLong(), (60000 / tempo).toLong(), callback)
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt
index b7e6d73..a2eaf90 100644
--- a/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt
+++ b/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt
@@ -31,25 +31,14 @@
if (Rhythm.on) android.R.drawable.ic_media_pause else android.R.drawable.ic_media_play
)
}
- binding.masterVolumeSlider.min = 0
- binding.masterVolumeSlider.max = 100
- binding.masterVolumeSlider.setOnSeekBarChangeListener(object :
- SeekBar.OnSeekBarChangeListener {
- override fun onProgressChanged(
- seekBar: SeekBar,
- progress: Int, fromUser: Boolean
- ) {
- setMasterVolume(progress.toDouble() / 100.0)
- binding.masterVolumeText.text = "Master volume: $progress%"
- }
-
- override fun onStartTrackingTouch(seekBar: SeekBar) {
- }
-
- override fun onStopTrackingTouch(seekBar: SeekBar) {
- }
- })
- binding.masterVolumeSlider.progress = 100
+ setupSlider(binding.masterVolumeSlider, 0, 100, 100) {
+ setMasterVolume(it.toDouble() / 100.0)
+ binding.masterVolumeText.text = "Master volume: $it%"
+ }
+ setupSlider(binding.tempoSlider, 50, 150, 90) {
+ Rhythm.setTempo(it)
+ binding.tempoText.text = "tempo: ${it}bpm"
+ }
val layout = RadioGroup.LayoutParams(
RadioGroup.LayoutParams.WRAP_CONTENT,
RadioGroup.LayoutParams.MATCH_PARENT
@@ -104,6 +93,33 @@
return binding.root
}
+ private fun setupSlider(
+ slider: SeekBar,
+ min: Int,
+ max: Int,
+ initialProgress: Int,
+ callback: (Int) -> Unit
+ ) {
+ slider.min = min
+ slider.max = max
+ slider.setOnSeekBarChangeListener(object :
+ SeekBar.OnSeekBarChangeListener {
+ override fun onProgressChanged(
+ seekBar: SeekBar,
+ progress: Int, fromUser: Boolean
+ ) {
+ callback(progress)
+ }
+
+ override fun onStartTrackingTouch(seekBar: SeekBar) {
+ }
+
+ override fun onStopTrackingTouch(seekBar: SeekBar) {
+ }
+ })
+ slider.progress = initialProgress
+ }
+
private fun putChords() {
binding.phraseDisplay.removeAllViews()
chordDisplays.clear()
diff --git a/app/src/main/java/com/lukas/music/util/Cycle.kt b/app/src/main/java/com/lukas/music/util/Cycle.kt
index f1ef055..4bf3ec5 100644
--- a/app/src/main/java/com/lukas/music/util/Cycle.kt
+++ b/app/src/main/java/com/lukas/music/util/Cycle.kt
@@ -44,12 +44,10 @@
if (size == 0) {
return null
}
- val callback: () -> Unit = {
+ this[index].step()
+ if (this[index].index == 0) {
super.step()
}
- this[index].wraparoundListeners += callback
- this[index].step()
- this[index].wraparoundListeners -= callback
for (callback in miniStepCallback) {
callback()
}
diff --git a/app/src/main/res/layout/fragment_play.xml b/app/src/main/res/layout/fragment_play.xml
index ace467f..09eac44 100644
--- a/app/src/main/res/layout/fragment_play.xml
+++ b/app/src/main/res/layout/fragment_play.xml
@@ -10,6 +10,29 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
+
+
+
+
+ app:layout_constraintTop_toBottomOf="@+id/tempoSlider" />