Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
out
.gradle
build
21 changes: 21 additions & 0 deletions appendix_a_coroutines/Drum Machine/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.10'
}

version '1.0-SNAPSHOT'

repositories {
mavenCentral()
}

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.1'
}

compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions appendix_a_coroutines/Drum Machine/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kotlin.code.style=official
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
172 changes: 172 additions & 0 deletions appendix_a_coroutines/Drum Machine/gradlew

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

84 changes: 84 additions & 0 deletions appendix_a_coroutines/Drum Machine/gradlew.bat

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

Binary file added appendix_a_coroutines/Drum Machine/high_hat.aiff
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions appendix_a_coroutines/Drum Machine/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rootProject.name = 'drummachine'

Binary file added appendix_a_coroutines/Drum Machine/snare.aiff
Binary file not shown.
38 changes: 38 additions & 0 deletions appendix_a_coroutines/Drum Machine/src/main/kotlin/Beats.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import java.io.File
import javax.sound.sampled.AudioSystem

import kotlinx.coroutines.*

suspend fun playBeats(beats: String, file: String) {
val parts = beats.split("x")
var count = 0
for (part in parts) {
count += part.length + 1
if (part == "") {
playSound(file)
} else {
delay(100 * (part.length + 1L))
if (count < beats.length) {
playSound(file)
}
}
}
}

fun playSound(file: String) {
val clip = AudioSystem.getClip()
val audioInputStream = AudioSystem.getAudioInputStream(
File(
file
)
)
clip.open(audioInputStream)
clip.start()
}

suspend fun main() {
runBlocking {
launch { playBeats("x-x-x-x-x-x-", "toms.aiff") }
playBeats("x-----x-----", "crash_cymbal.aiff")
}
}
Binary file added appendix_a_coroutines/Drum Machine/toms.aiff
Binary file not shown.
12 changes: 12 additions & 0 deletions chapter01/MyFirstApp/MyFirstApp.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
</component>
</module>
3 changes: 3 additions & 0 deletions chapter01/MyFirstApp/src/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fun main(args: Array<String>) {
println("Pow!")
}
12 changes: 12 additions & 0 deletions chapter02/PhraseOMatic/PhraseOMatic.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
</component>
</module>
16 changes: 16 additions & 0 deletions chapter02/PhraseOMatic/src/PhraseOMatic.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
fun main(args: Array<String>){
val wordArray1 = arrayOf("24/7", "multi-tier", "B-to-B", "dynamic", "pervasive")
val wordArray2 = arrayOf("empowered", "leveraged", "aligned", "targeted")
val wordArray3 = arrayOf("process", "paradigm", "solution", "portal", "vision")

val arraySize1 = wordArray1.size
val arraySize2 = wordArray2.size
val arraySize3 = wordArray3.size

val rand1 = (Math.random() * arraySize1).toInt()
val rand2 = (Math.random() * arraySize2).toInt()
val rand3 = (Math.random() * arraySize3).toInt()

val phrase = "${wordArray1[rand1]} ${wordArray2[rand2]} ${wordArray3[rand3]}"
println(phrase)
}
Loading