Last active
September 12, 2019 23:25
-
-
Save dkandalov/e39975744ddab461d4b9a98bebc45d57 to your computer and use it in GitHub Desktop.
tidal for intellij
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| :set -XOverloadedStrings | |
| :set prompt "" | |
| :set prompt-cont "" | |
| import Sound.Tidal.Context | |
| -- total latency = oLatency + cFrameTimespan | |
| tidal <- startTidal (superdirtTarget {oLatency = 0.1, oAddress = "127.0.0.1", oPort = 57120}) (defaultConfig {cFrameTimespan = 1/20}) | |
| :{ | |
| let p = streamReplace tidal | |
| hush = streamHush tidal | |
| list = streamList tidal | |
| mute = streamMute tidal | |
| unmute = streamUnmute tidal | |
| solo = streamSolo tidal | |
| unsolo = streamUnsolo tidal | |
| once = streamOnce tidal | |
| asap = once | |
| nudgeAll = streamNudgeAll tidal | |
| all = streamAll tidal | |
| resetCycles = streamResetCycles tidal | |
| setcps = asap . cps | |
| xfade i = transition tidal True (Sound.Tidal.Transition.xfadeIn 4) i | |
| xfadeIn i t = transition tidal True (Sound.Tidal.Transition.xfadeIn t) i | |
| histpan i t = transition tidal True (Sound.Tidal.Transition.histpan t) i | |
| wait i t = transition tidal True (Sound.Tidal.Transition.wait t) i | |
| waitT i f t = transition tidal True (Sound.Tidal.Transition.waitT f t) i | |
| jump i = transition tidal True (Sound.Tidal.Transition.jump) i | |
| jumpIn i t = transition tidal True (Sound.Tidal.Transition.jumpIn t) i | |
| jumpIn' i t = transition tidal True (Sound.Tidal.Transition.jumpIn' t) i | |
| jumpMod i t = transition tidal True (Sound.Tidal.Transition.jumpMod t) i | |
| mortal i lifespan release = transition tidal True (Sound.Tidal.Transition.mortal lifespan release) i | |
| interpolate i = transition tidal True (Sound.Tidal.Transition.interpolate) i | |
| interpolateIn i t = transition tidal True (Sound.Tidal.Transition.interpolateIn t) i | |
| clutch i = transition tidal True (Sound.Tidal.Transition.clutch) i | |
| clutchIn i t = transition tidal True (Sound.Tidal.Transition.clutchIn t) i | |
| anticipate i = transition tidal True (Sound.Tidal.Transition.anticipate) i | |
| anticipateIn i t = transition tidal True (Sound.Tidal.Transition.anticipateIn t) i | |
| forId i t = transition tidal False (Sound.Tidal.Transition.mortalOverlay t) i | |
| d1 = p 1 . (|< orbit 0) | |
| d2 = p 2 . (|< orbit 1) | |
| d3 = p 3 . (|< orbit 2) | |
| d4 = p 4 . (|< orbit 3) | |
| d5 = p 5 . (|< orbit 4) | |
| d6 = p 6 . (|< orbit 5) | |
| d7 = p 7 . (|< orbit 6) | |
| d8 = p 8 . (|< orbit 7) | |
| d9 = p 9 . (|< orbit 8) | |
| d10 = p 10 . (|< orbit 9) | |
| d11 = p 11 . (|< orbit 10) | |
| d12 = p 12 . (|< orbit 11) | |
| d13 = p 13 | |
| d14 = p 14 | |
| d15 = p 15 | |
| d16 = p 16 | |
| :} | |
| :{ | |
| let setI = streamSetI tidal | |
| setF = streamSetF tidal | |
| setS = streamSetS tidal | |
| setR = streamSetI tidal | |
| setB = streamSetB tidal | |
| :} | |
| :set prompt "tidal> " |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.intellij.openapi.Disposable | |
| import com.intellij.openapi.actionSystem.AnActionEvent | |
| import com.intellij.openapi.editor.Editor | |
| import com.intellij.openapi.util.Disposer | |
| import liveplugin.PluginUtil | |
| import static liveplugin.PluginUtil.* | |
| import static liveplugin.PluginUtil.getGlobalVar | |
| def tidalBootFilePath = "$pluginPath/BootTidal.hs" | |
| class TidalProcess { | |
| private final String tidalBootFilePath | |
| private Process ghciProcess | |
| private Writer stdout | |
| TidalProcess(String tidalBootFilePath) { | |
| this.tidalBootFilePath = tidalBootFilePath | |
| } | |
| def start(Closure onInput) { | |
| ghciProcess = Runtime.getRuntime().exec("/usr/local/bin/ghci") | |
| stdout = ghciProcess.outputStream.newWriter() | |
| def stdoutConsumingThread = new Thread(new Runnable() { | |
| @Override void run() { | |
| show("running") | |
| try { | |
| def errorStream = ghciProcess.errorStream.newReader() | |
| def inputStream = ghciProcess.inputStream.newReader() | |
| while (isRunning()) { | |
| def input = readLines(inputStream) | |
| if (!input.isEmpty()) show(input) | |
| def errors = readLines(errorStream) | |
| if (!errors.isEmpty()) show(errors) | |
| Thread.sleep(200) | |
| } | |
| } catch (IOException ignored) { | |
| } | |
| show("finished") | |
| } | |
| }) | |
| stdoutConsumingThread.start() | |
| new File(tidalBootFilePath).readLines().each { line -> write(line) } | |
| this | |
| } | |
| private static String readLines(BufferedReader inputStream) { | |
| def lines = "" | |
| while (inputStream.ready()) { | |
| def line = inputStream.readLine() | |
| lines += line + "\n" | |
| } | |
| lines | |
| } | |
| def write(String s) { | |
| try { | |
| stdout.append(s + "\n") | |
| stdout.flush() | |
| } catch (Exception e) { | |
| show(e) | |
| } | |
| } | |
| def isRunning() { | |
| ghciProcess != null && ghciProcess.alive | |
| } | |
| def stop() { | |
| stdout.close() | |
| ghciProcess.destroyForcibly() | |
| this | |
| } | |
| } | |
| registerAction("StartTidal") { AnActionEvent event -> | |
| changeGlobalVar("tidalProcess") { def process -> | |
| if (process?.isRunning()) { | |
| show("Tidal is already started") | |
| process | |
| } else { | |
| show("Started tidal") | |
| new TidalProcess(tidalBootFilePath).start { List<String> inputLines -> | |
| inputLines.each { show(it) } | |
| } | |
| } | |
| } | |
| } | |
| registerAction("MessageTidal") { AnActionEvent event -> | |
| def editor = currentEditorIn(event.project) | |
| def text = editor.selectionModel.getSelectedText(true) | |
| if (!text.isEmpty() && !text.replace("\n", "").isAllWhitespace()) { | |
| getGlobalVar("tidalProcess")?.write(text) | |
| } | |
| // d4 $ sound "arpy" | |
| // hush | |
| } | |
| registerAction("HushTidal") { AnActionEvent event -> | |
| getGlobalVar("tidalProcess")?.write("hush") | |
| } | |
| registerAction("StopTidal") { AnActionEvent event -> | |
| changeGlobalVar("tidalProcess") { def process -> | |
| if (process?.isRunning()) { | |
| show("Stopped tidal") | |
| process.stop() | |
| } else { | |
| show("Tidal is already stopped") | |
| process | |
| } | |
| } | |
| } | |
| if (!isIdeStartup) show("Reloaded tidal plugin") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment