Create new module: smnp.music.tools

This commit is contained in:
2020-03-14 19:38:20 +01:00
parent c5ac06a6f6
commit 769e9bf936
4 changed files with 49 additions and 0 deletions

View File

View File

@@ -0,0 +1,7 @@
version=0.0.1
pluginVersion=0.1
pluginId=smnp.music.tools
pluginClass=
pluginProvider=Bartłomiej Pluta
pluginDependencies=

View File

@@ -0,0 +1,9 @@
package io.smnp.ext.musictools
import io.smnp.ext.LanguageModuleProvider
import org.pf4j.Extension
@Extension
class MusicToolsModule : LanguageModuleProvider("smnp.music.tools") {
override fun dependencies() = listOf("smnp.audio.midi", "smnp.music")
}

View File

@@ -0,0 +1,33 @@
function metronome(bpm: int = 120, beats: int = 4, accent: note = @A#2, beat: note = @F#2) {
measure = [accent] + ((beats-1) ^ beat)
true ^ midi({ bpm -> bpm }, { 10 -> [measure] });
}
function alert(melody: string = "beep") {
melodies = {
beep -> ["i:108", @c5, 4, @c5, 1, 4],
bell -> ["i:108", @c5:8, @db5:8],
alarm1 -> ["i:108", (range(@g, @g5) as n ^ n.withDuration(32))].flatten(),
alarm2 -> ["i:108", (range(@g, @g5) as n ^ n.withDuration(32)), -(range(@c, @c5) as n ^ n.withDuration(32))].flatten()
};
if(not melodies.containsKey(melody)) {
throw "Unknown melody with name of '" + melody + "'";
}
true ^ midi({ bpm -> 400 }, melodies.get(melody));
}
function alert(cycles: int, melody: string = "beep") {
melodies = {
beep -> ["i:108", @c5, 4, @c5, 1, 4],
bell -> ["i:108", @c5:8, @db5:8],
alarm1 -> ["i:108", (range(@g, @g5) as n ^ n.withDuration(32))].flatten(),
alarm2 -> ["i:108", (range(@g, @g5) as n ^ n.withDuration(32)), -(range(@c, @c5) as n ^ n.withDuration(32))].flatten()
};
if(not melodies.containsKey(melody)) {
throw "Unknown melody with name of '" + melody + "'";
}
cycles ^ midi({ bpm -> 400 }, melodies.get(melody));
}