Skip to content

Commit

Permalink
- Use chromatic tuner without string view, when instrument has no str…
Browse files Browse the repository at this point in the history
…ings

- Update dependencies
  • Loading branch information
thetwom committed May 15, 2023
1 parent fd014e8 commit 6f01348
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 13 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ android {
applicationId "de.moekadu.tuner"
minSdkVersion 23
targetSdkVersion 33
versionCode 26
versionName "6.0.0"
versionCode 27
versionName "6.1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
resConfigs "cs", "de", "en", "fr"
resourceConfigurations += ['cs', 'de', 'en', 'fr']
}
buildTypes {
release {
Expand All @@ -23,6 +23,10 @@ android {
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "11"
}
Expand All @@ -31,16 +35,16 @@ android {

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.activity:activity-ktx:1.6.1'
implementation 'androidx.fragment:fragment-ktx:1.5.5'
implementation 'androidx.activity:activity-ktx:1.7.1'
implementation 'androidx.fragment:fragment-ktx:1.5.7'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.5.1"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.1"
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.preference:preference-ktx:1.2.0'
implementation 'com.google.android.material:material:1.9.0-alpha02'
implementation("androidx.recyclerview:recyclerview:1.2.1")
implementation 'com.google.android.material:material:1.9.0'
implementation("androidx.recyclerview:recyclerview:1.3.0")
implementation("androidx.recyclerview:recyclerview-selection:1.1.0")
testImplementation 'junit:junit:4.13.2'
testImplementation 'android.arch.core:core-testing:1.1.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class TunerFragmentSimple : Fragment() {
stringViewChangeId = -1

if (model.settingsChangeId > stringViewChangeId) {
stringView?.visibility = if (model.isVisible) View.VISIBLE else View.GONE
stringView?.enableExtraPadding = model.useExtraPadding
val printer = model.noteNamePrinter
if (model.instrument.isChromatic && printer != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class PitchHistoryModel {
// handle tuning target
if (tuningTarget != null) {
// Log.v("Tuner", "PitchHistoryModel.changeSettings: tuningTarget=$tuningTarget")
targetNote = if (tuningTarget.isPartOfInstrument) tuningTarget.note else null
targetNote = if (tuningTarget.isPartOfInstrument || tuningTarget.instrumentHasNoStrings) tuningTarget.note else null
targetNoteFrequency = tuningTarget.frequency
recomputeYRange = true
recomputeToleranceBounds = true
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/de/moekadu/tuner/models/StringsModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class StringsModel {
var highlightChangeId = 0
private set

var isVisible = true
private set

fun changeSettings(
instrument: Instrument? = null,
musicalScale: MusicalScale? = null,
Expand All @@ -54,6 +57,7 @@ class StringsModel {
if (this.instrument != it) {
settingsChangeId = changeId
doCheckInstrumentCompatibility = true
isVisible = !(!instrument.isChromatic && instrument.strings.isEmpty())
this.instrument = it
}
}
Expand Down
19 changes: 14 additions & 5 deletions app/src/main/java/de/moekadu/tuner/notedetection/TuningTarget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import de.moekadu.tuner.temperaments.MusicalScale
data class TuningTarget(
val note: MusicalNote,
val frequency: Float,
val isPartOfInstrument: Boolean
val isPartOfInstrument: Boolean,
val instrumentHasNoStrings: Boolean
)

class TuningTargetComputer(
Expand All @@ -32,7 +33,8 @@ class TuningTargetComputer(
return TuningTarget(
userDefinedTargetNote,
musicalScale.getNoteFrequency(index),
sortedAndDistinctInstrumentStrings.isNotePartOfInstrument(userDefinedTargetNote)
isPartOfInstrument = sortedAndDistinctInstrumentStrings.isNotePartOfInstrument(userDefinedTargetNote),
instrumentHasNoStrings = !instrument.isChromatic && instrument.strings.isEmpty()
)
}
}
Expand All @@ -42,7 +44,8 @@ class TuningTargetComputer(
return TuningTarget(
musicalScale.referenceNote,
musicalScale.referenceFrequency,
sortedAndDistinctInstrumentStrings.isNotePartOfInstrument(musicalScale.referenceNote)
isPartOfInstrument = sortedAndDistinctInstrumentStrings.isNotePartOfInstrument(musicalScale.referenceNote),
instrumentHasNoStrings = !instrument.isChromatic && instrument.strings.isEmpty()
)
}

Expand All @@ -54,14 +57,20 @@ class TuningTargetComputer(
return TuningTarget(
detectedTargetNote,
musicalScale.getNoteFrequency(index),
true
isPartOfInstrument = true,
instrumentHasNoStrings = !instrument.isChromatic && instrument.strings.isEmpty()
)
}

// no instrument note available, return the closest chromatic
val chromaticTargetNote = targetNoteAutoDetectionChromatic.detect(frequency, previousTargetNote)
// the returned note will always be non null for chromatic instruments and non-zero frequencies
val index = musicalScale.getNoteIndex(chromaticTargetNote!!)
return TuningTarget(chromaticTargetNote, musicalScale.getNoteFrequency(index), false)
return TuningTarget(
chromaticTargetNote,
musicalScale.getNoteFrequency(index),
isPartOfInstrument = false,
instrumentHasNoStrings = !instrument.isChromatic && instrument.strings.isEmpty()
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ class TunerViewModel(

/** Current tuning target. */
private val _tuningTarget = MutableStateFlow(
TuningTarget(pref.musicalScale.value.referenceNote, pref.musicalScale.value.referenceFrequency, false)
TuningTarget(
pref.musicalScale.value.referenceNote,
pref.musicalScale.value.referenceFrequency,
isPartOfInstrument = false,
instrumentHasNoStrings = !instrument.value.instrument.isChromatic && instrument.value.instrument.strings.isEmpty()
)
)
private val tuningTarget = _tuningTarget.asStateFlow()

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.7.20'
ext.kotlin_version = '1.8.21'
repositories {
google()
mavenCentral()

}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
classpath 'com.android.tools.build:gradle:8.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ android.useAndroidX=true
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip

0 comments on commit 6f01348

Please # to comment.