Skip to content

Commit

Permalink
chore: update gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromsantos committed Mar 12, 2024
1 parent 7009045 commit 9633577
Show file tree
Hide file tree
Showing 24 changed files with 1,236 additions and 1,111 deletions.
10 changes: 6 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,21 @@ dependencies {
}

compileJava {
sourceCompatibility = 1.8
sourceCompatibility = 17
targetCompatibility = 17
}

compileTestJava {
sourceCompatibility = 1.8
sourceCompatibility = 17
targetCompatibility = 17
}

compileKotlin {
kotlinOptions.jvmTarget = 1.8
kotlinOptions.jvmTarget = 17
}

compileTestKotlin {
kotlinOptions.jvmTarget = 1.8
kotlinOptions.jvmTarget = 17
}

tasks.withType(Test) {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.4-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
67 changes: 37 additions & 30 deletions src/main/kotlin/org/harris/chords/Chord.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@ import org.harris.notes.Pitch

interface Chord {
fun pitches(): Array<Pitch>

fun bass(): Pitch

fun lead(): Pitch

fun name(): String

fun pitchForFunction(function: ChordFunction): Pitch

fun remove(function: ChordFunction): Chord

fun invert(): Chord

fun drop2(): Chord

fun drop3(): Chord

fun closed(): Chord
}

Expand Down Expand Up @@ -73,19 +82,19 @@ abstract class BaseChord : Chord {
}

abstract override fun remove(function: ChordFunction): Chord

abstract override fun invert(): Chord
}

class ClosedChord : BaseChord {

internal constructor(root: Pitch, pattern: ChordPattern) : super(root, pattern) {}

internal constructor(root: ChordPitch, pattern: ChordPattern) : super(root.pitch, pattern) {}

internal constructor(
root: ChordPitch,
pattern: ChordPattern,
notes: ChordPitches
notes: ChordPitches,
) : super(root, pattern, notes) {}

override fun remove(function: ChordFunction): Chord {
Expand All @@ -102,43 +111,41 @@ class ClosedChord : BaseChord {
}

class Drop2Chord
internal constructor(root: ChordPitch, pattern: ChordPattern, notes: ChordPitches) :
internal constructor(root: ChordPitch, pattern: ChordPattern, notes: ChordPitches) :
BaseChord(root, pattern, notes) {
override fun remove(function: ChordFunction): Chord {
return Drop2Chord(root, pattern, pitches.remove(function))
}

override fun remove(function: ChordFunction): Chord {
return Drop2Chord(root, pattern, pitches.remove(function))
}

override fun invert(): Chord {
val invertedNotes = pitches.rotate(3).rotateLastSkipFirst().rotateLastSkipFirst()
override fun invert(): Chord {
val invertedNotes = pitches.rotate(3).rotateLastSkipFirst().rotateLastSkipFirst()

return Drop2Chord(root, pattern, invertedNotes)
}
return Drop2Chord(root, pattern, invertedNotes)
}

override fun drop2(): Chord {
return this
override fun drop2(): Chord {
return this
}
}
}

class Drop3Chord
internal constructor(root: ChordPitch, pattern: ChordPattern, notes: ChordPitches) :
internal constructor(root: ChordPitch, pattern: ChordPattern, notes: ChordPitches) :
BaseChord(root, pattern, notes) {
override fun remove(function: ChordFunction): Chord {
return Drop3Chord(root, pattern, pitches.remove(function))
}

override fun remove(function: ChordFunction): Chord {
return Drop3Chord(root, pattern, pitches.remove(function))
}

override fun invert(): Chord {
val invertedNotes =
pitches.rotate(2)
.rotateLastSkipFirst(2)
.rotateLastSkipFirst(1)
.rotateLastSkipFirst(1)
override fun invert(): Chord {
val invertedNotes =
pitches.rotate(2)
.rotateLastSkipFirst(2)
.rotateLastSkipFirst(1)
.rotateLastSkipFirst(1)

return Drop3Chord(root, pattern, invertedNotes)
}
return Drop3Chord(root, pattern, invertedNotes)
}

override fun drop3(): Chord {
return this
override fun drop3(): Chord {
return this
}
}
}
18 changes: 12 additions & 6 deletions src/main/kotlin/org/harris/chords/ChordFunction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ enum class ChordFunction {
Seventh,
Ninth,
Eleventh,
Thirteenth;
Thirteenth,
;

companion object {
internal fun functionForInterval(interval: Interval): ChordFunction {
Expand All @@ -21,19 +22,24 @@ enum class ChordFunction {
Interval.MajorSecond,
Interval.MinorSecond,
Interval.PerfectFourth,
Interval.AugmentedFourth -> Third
Interval.AugmentedFourth,
-> Third
Interval.PerfectFifth,
Interval.DiminishedFifth,
Interval.AugmentedFifth -> Fifth
Interval.AugmentedFifth,
-> Fifth
Interval.MinorSixth,
Interval.MajorSixth -> Sixth
Interval.MajorSixth,
-> Sixth
Interval.MajorSeventh,
Interval.MinorSeventh,
Interval.DiminishedSeventh -> Seventh
Interval.DiminishedSeventh,
-> Seventh
Interval.MajorNinth,
Interval.MinorNinth,
Interval.PerfectEleventh,
Interval.AugmentedEleventh -> Eleventh
Interval.AugmentedEleventh,
-> Eleventh
Interval.MajorThirteenth -> Thirteenth
else -> Root
}
Expand Down
9 changes: 6 additions & 3 deletions src/main/kotlin/org/harris/chords/ChordPattern.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ enum class ChordPattern(private val patternName: String, private val abbreviatio
Sus2Augmented("Major", "Maj", listOf(MajorSecond, AugmentedFifth)),
Sus4("Major", "Maj", listOf(PerfectFourth, PerfectFifth)),
Sus4Diminished("Major", "Maj", listOf(PerfectFourth, DiminishedFifth)),
Sus4Augmented("Major", "Maj", listOf(PerfectFourth, AugmentedFifth));
Sus4Augmented("Major", "Maj", listOf(PerfectFourth, AugmentedFifth)),
;

fun createChord(root: Pitch): ClosedChord {
return ClosedChord(root, this)
Expand All @@ -75,6 +76,8 @@ enum class ChordPattern(private val patternName: String, private val abbreviatio
.toTypedArray()
}

private fun createChordNote(it: Interval, root: Pitch) =
ChordPitch(root.transpose(it), ChordFunction.functionForInterval((it)))
private fun createChordNote(
it: Interval,
root: Pitch,
) = ChordPitch(root.transpose(it), ChordFunction.functionForInterval((it)))
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.harris

inline fun <T> Array<T>.rotate(n: Int) =
let { sliceArray(n until size) + sliceArray(0 until n) }
inline fun <T> Array<T>.rotate(n: Int) = let { sliceArray(n until size) + sliceArray(0 until n) }

inline fun <reified T> Array<T>.moveElement(fromIndex: Int, toIndex: Int): Array<T> =
toMutableList().apply { add(toIndex, removeAt(fromIndex)) }.toTypedArray()
inline fun <reified T> Array<T>.moveElement(
fromIndex: Int,
toIndex: Int,
): Array<T> = toMutableList().apply { add(toIndex, removeAt(fromIndex)) }.toTypedArray()
32 changes: 17 additions & 15 deletions src/main/kotlin/org/harris/keys/Key.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,32 @@ enum class Key(private val root: Pitch, private val accidentals: Int) {
FSharpMinor(FSharp, 3),
GMinor(G, -2),
GSharpMinor(GSharp, 5),
EFlatMinor(EFlat, -6);
EFlatMinor(EFlat, -6),
;

private fun flatKey(): Set<Pitch> {
return (
fifths
.asReversed()
.drop(abs(this.accidentals))
)
)
.union(
fifths
.asReversed()
.take(abs(this.accidentals))
.map { it.flat() }
.map { it.flat() },
)
}

private fun sharpKey(): Set<Pitch> {
return (
fifths
.drop(this.accidentals)
)
)
.union(
fifths
.take(this.accidentals)
.map { it.sharp() }
.map { it.sharp() },
)
}

Expand All @@ -87,19 +88,20 @@ enum class Key(private val root: Pitch, private val accidentals: Int) {
.union(
notes
.sortedBy { it.value() }
.takeWhile { it != this.root }
.takeWhile { it != this.root },
)
}

companion object {
private val fifths = listOf(
F,
C,
G,
D,
A,
E,
B
)
private val fifths =
listOf(
F,
C,
G,
D,
A,
E,
B,
)
}
}
4 changes: 2 additions & 2 deletions src/main/kotlin/org/harris/notes/Interval.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.harris.notes
enum class Interval(
private val intervalName: String,
private val abreviature: String,
private val distance: Int
private val distance: Int,
) {
Unison("Unisson", "U", 0) {
override fun invert(): Interval = PerfectOctave
Expand Down Expand Up @@ -82,7 +82,7 @@ enum class Interval(
},
MajorThirteenth("Major Thirteenth", "M13", 21) {
override fun invert(): Interval = MinorThird
};
}, ;

abstract fun invert(): Interval
}
76 changes: 38 additions & 38 deletions src/main/kotlin/org/harris/notes/Note.kt
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
package org.harris.notes

import org.harris.notes.NoteDuration.Whole
import org.harris.scales.Scale
import org.harris.scales.ScaleDegree
import org.harris.scales.ScalePattern

data class Note(
private val pitch: Pitch,
private val noteInScale: NoteInScale = NoteInScale.chromaticNote(pitch),
private val duration: NoteDuration = Whole
) {

fun flat(): Note = Note(pitch.flat(), NoteInScale.chromaticNote(pitch), duration)

fun sharp(): Note = Note(pitch.sharp(), NoteInScale.chromaticNote(pitch), duration)

fun above(): Note = Note(noteInScale.abovePitch(), noteInScale.above(), duration)

fun below(): Note = Note(noteInScale.belowPitch(), noteInScale.below(), duration)
}

data class NoteInScale(val scalePattern: ScalePattern, val root: Pitch, val degree: ScaleDegree) {

fun root(): Pitch = root

fun above(): NoteInScale = NoteInScale(scalePattern, root, degree.above())
fun below(): NoteInScale = NoteInScale(scalePattern, root, degree.below())

fun abovePitch(): Pitch = Scale(scalePattern, root).pitch(degree.above())
fun belowPitch(): Pitch = Scale(scalePattern, root).pitch(degree.below())

companion object {
fun chromaticNote(pitch: Pitch): NoteInScale {
return NoteInScale(ScalePattern.Chromatic, pitch, ScaleDegree.I)
}
}
}
package org.harris.notes

import org.harris.notes.NoteDuration.Whole
import org.harris.scales.Scale
import org.harris.scales.ScaleDegree
import org.harris.scales.ScalePattern

data class Note(
private val pitch: Pitch,
private val noteInScale: NoteInScale = NoteInScale.chromaticNote(pitch),
private val duration: NoteDuration = Whole,
) {
fun flat(): Note = Note(pitch.flat(), NoteInScale.chromaticNote(pitch), duration)

fun sharp(): Note = Note(pitch.sharp(), NoteInScale.chromaticNote(pitch), duration)

fun above(): Note = Note(noteInScale.abovePitch(), noteInScale.above(), duration)

fun below(): Note = Note(noteInScale.belowPitch(), noteInScale.below(), duration)
}

data class NoteInScale(val scalePattern: ScalePattern, val root: Pitch, val degree: ScaleDegree) {
fun root(): Pitch = root

fun above(): NoteInScale = NoteInScale(scalePattern, root, degree.above())

fun below(): NoteInScale = NoteInScale(scalePattern, root, degree.below())

fun abovePitch(): Pitch = Scale(scalePattern, root).pitch(degree.above())

fun belowPitch(): Pitch = Scale(scalePattern, root).pitch(degree.below())

companion object {
fun chromaticNote(pitch: Pitch): NoteInScale {
return NoteInScale(ScalePattern.Chromatic, pitch, ScaleDegree.I)
}
}
}
3 changes: 2 additions & 1 deletion src/main/kotlin/org/harris/notes/NoteDuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package org.harris.notes
enum class NoteDuration(private val durationName: String, private val multiplier: Float) {
Whole("Whole", 1.0F),
Half("Half", 1.0F / 2.0F),
Quarter("Quarter", 1.0F / 4.0F);
Quarter("Quarter", 1.0F / 4.0F),
;

fun toBeats(timeSignature: Float): Float {
return this.multiplier * timeSignature
Expand Down
Loading

0 comments on commit 9633577

Please sign in to comment.