Discussion:
[haskell-art] ANN: hsc3-process-0.8 and hsc3-server 0.5
Stefan Kersten
2012-12-20 13:03:13 UTC
Permalink
I am happy to announce the release of version 0.8 of hsc3-process [1] and version 0.5 of hsc3-server [2], both providing additional features and abstractions for the excellent hsc3 interface [3] to the SuperCollider synthesis server [4].

hsc3-process allows to start external scsynth processes and run actions that communicate through the associated OpenSoundControl transport.

hsc3-server builds on hsc3 and hsc3-process and adds the following features:

* A `Server' monad for accessing synthesis server state from concurrent threads,
* Resource ID allocators for nodes, buffers and buses,
* A composable `Request' abstraction that allows to assemble synchronous and asynchronous server commands into OpenSoundControl bundles for efficient scheduling,
* A type-safe interface to the SuperCollider synthesis server command set.

hsc3-server has been in use internally for some time but this is the first release that is ready for consumption by the general public. Have a look at some examples here [5]. Any feedback welcome!

Happy synthesis!

[1] http://hackage.haskell.org/package/hsc3-process
[2] http://hackage.haskell.org/package/hsc3-server
[3] http://hackage.haskell.org/package/hsc3
[4] http://supercollider.sourceforge.net/
[5] https://github.com/kaoskorobase/hsc3-server/tree/master/examples
Miguel Negrao
2012-12-20 13:16:38 UTC
Permalink
Post by Stefan Kersten
I am happy to announce the release of version 0.8 of hsc3-process [1] and version 0.5 of hsc3-server [2], both providing additional features and abstractions for the excellent hsc3 interface [3] to the SuperCollider synthesis server [4].
* A `Server' monad for accessing synthesis server state from concurrent threads,
Hi Stefan,

This is great news !! I’ve been using a bit v0.5 of hsc3-server and hsc3-process and it’s very nice indeed !

I leave an example of running an interactive session in emacs using haskell mode haskell-hsc3 mode from hsc3:

import qualified Streamero.MonadServer as MS
import qualified Sound.SC3.Server.State.Monad
import Sound.SC3.Server.State.Monad.Command
import Sound.SC3.Server.State.Monad.Process
import Sound.SC3.UGen

--Start up system
engine <- MS.new withDefaultSynth
let send a = MS.execute engine $ exec_ a
r <- MS.execute engine rootNode

let sine = (out 0 (sinOsc AR (control KR "freq" 400) 0 * 0.1))

-- select and run with c-c c-e
synth <- send $ do {
sd <- d_recv "hsc3-server:sine" sine;
s_new sd AddToTail r [("freq", 440), ("amp", 0.2)];
}

send $ n_set synth [ ("freq", 200)]

send $ n_free synth

Writing long functions or expressions in emacs to be run in ghci is a bit difficult because you can’t use the normal indentation rules (at least I haven’t figured out how), so one possibility would be to just write those functions in a .hs file and load the file to ghci, but every time one does that the previous bindings are destroyed and loose access to the server that we booted, and any resources on it, so that doesn’t work for interaction with a sc server via hsc3-server. Does anyone have any tips about this ? Is it possible somehow to load a file to ghci and keep the bindings or is there a way to write haskell code with indentation based expression boundaries and evaluate that in ghci ?

best,
Miguel
Henning Thielemann
2012-12-20 13:42:29 UTC
Permalink
Post by Miguel Negrao
Writing long functions or expressions in emacs to be run in ghci is a
bit difficult because you can’t use the normal indentation rules (at
least I haven’t figured out how), so one possibility would be to just
write those functions in a .hs file and load the file to ghci, but every
time one does that the previous bindings are destroyed and loose access
to the server that we booted, and any resources on it, so that doesn’t
work for interaction with a sc server via hsc3-server. Does anyone have
any tips about this ?
Instead of indentation you might break big expressions into small
expressions and local functions using 'let'. Would that help? Nonetheless,
you lose what you wrote if you leave GHCi. (If you are lucky some lines
are stored if you re-enter GHCi and can be retrieved with cursor-up.)
Rohan Drape
2012-12-20 21:23:47 UTC
Permalink
Post by Miguel Negrao
is there a way to write haskell code with indentation based expression
boundaries and evaluate that in ghci ?
You can easily write a function to remove layout.

import Language.Haskell.Exts.Parser {- haskell-src-exts -}
import Language.Haskell.Exts.Pretty

unlayout :: String -> String
unlayout s =
let m = defaultMode {layout = PPNoLayout}
ParseOk r = parseExp s
in prettyPrintWithMode m r

-- > unlayout t0 == "let { a = 5; b = 6} in a + b"
t0 :: String
t0 = unlines ["let a = 5"
," b = 6"
,"in a + b"]

-- > unlayout t1 == unlayout t0
t1 :: String
t1 = "let {a = 5;b = 6} in a + b"

main :: IO ()
main = getContents >>= putStrLn . unlayout

It's not in hsc3 because haskell-src-exts seems a major dependency for a
three line function...

You can run the 'unlayout' process over outgoing expressions in emacs
using 'shell-command-to-string'.

Best,
Rohan
Henning Thielemann
2012-12-20 22:30:53 UTC
Permalink
Post by Rohan Drape
You can run the 'unlayout' process over outgoing expressions in emacs
using 'shell-command-to-string'.
You can define GHCi commands (those with leading colon) based on Haskell
functions. Maybe you can create an :unlayout command?
Miguel Negrao
2012-12-22 21:37:21 UTC
Permalink
Post by Rohan Drape
Post by Miguel Negrao
is there a way to write haskell code with indentation based expression
boundaries and evaluate that in ghci ?
You can easily write a function to remove layout.
...
Post by Rohan Drape
You can run the 'unlayout' process over outgoing expressions in emacs
using 'shell-command-to-string’.
Hi Rohan,

That is very promising but I don’t seem to know enough about lisp and emacs to be able to cook a function to do what you suggest. I tried this

(defun hsc3-run-with-layout ()
"Send the current region to the interpreter with layout."
(interactive)
(let* ((s (region-string)))
(hsc3-send-string (shell-command-to-string (concatenate "/Users/miguelnegrao/Development/Haskell/projects/unlayout/unlayout " s)))))

but I get this error:

ad-Orig-error: Not a sequence type name: /Users/miguelnegrao/Development/Haskell/projects/unlayout/unlayout

best,
Miguel
Miguel Negrao
2013-01-04 17:25:29 UTC
Permalink
Post by Miguel Negrao
Writing long functions or expressions in emacs to be run in ghci is a bit difficult because you can’t use the normal indentation rules (at least I haven’t figured out how), so one possibility would be to just write those functions in a .hs file and load the file to ghci, but every time one does that the previous bindings are destroyed and loose access to the server that we booted, and any resources on it, so that doesn’t work for interaction with a sc server via hsc3-server. Does anyone have any tips about this ? Is it possible somehow to load a file to ghci and keep the bindings or is there a way to write haskell code with indentation based expression boundaries and evaluate that in ghci ?
I’m happy to report that I’ve found that leksah has a quite nice and working interactive ghci pane. It has a window for writing code (a scratch buffer), where one can use indentation based rules, and it has another pane with all the variables defined so far. To evaluate code one either selects a portion of code or puts the cursor on a line and hits ctrl-enter. It feels very interactive.
If I want to run multiple IO actions in ghci and bind the result to “variables” that I can use later, is this the best way ?

(engine,r,send) <- do
engine <- MS.new withDefaultSynth
let send a = MS.execute engine $ exec_ a
r <- MS.execute engine rootNode
return (engine, r, send)

best,
Miguel
Henning Thielemann
2013-01-04 17:35:10 UTC
Permalink
I’m happy to report that I’ve found that leksah has a quite nice and
working interactive ghci pane. It has a window for writing code (a
scratch buffer), where one can use indentation based rules, and it has
another pane with all the variables defined so far. To evaluate code one
either selects a portion of code or puts the cursor on a line and hits
ctrl-enter. It feels very interactive.
Thank you for this hint!
If I want to run multiple IO actions in ghci and bind the result to
“variables” that I can use later, is this the best way ?
(engine,r,send) <- do
engine <- MS.new withDefaultSynth
let send a = MS.execute engine $ exec_ a
r <- MS.execute engine rootNode
return (engine, r, send)
In GHCi you could just write

Prelude> engine <- MS.new withDefaultSynth
Prelude> let send a = MS.execute engine $ exec_ a
Prelude> r <- MS.execute engine rootNode


But if you want to bundle all three actions, then your do-block is
certainly the best way.
Luke Iannini
2013-01-04 23:38:08 UTC
Permalink
And just to note, it should be possible to add support for multi-line GHCi
evaluation in emacs — you just need to wrap the lines being sent in :{ and
:} (you can use those commands in ghci to write and run multiline code).

I have this in my SublimeGHCi plugin for Sublime Text
https://github.com/lukexi/SublimeGHCi/blob/master/interpret_haskell.py
but beware it's an alpha that I haven't played with in a while;
incidentally I /also/ wrote it for playing with hsc3 :D

Best
Luke


On Fri, Jan 4, 2013 at 9:35 AM, Henning Thielemann <
I’m happy to report that I’ve found that leksah has a quite nice and
Post by Miguel Negrao
working interactive ghci pane. It has a window for writing code (a scratch
buffer), where one can use indentation based rules, and it has another pane
with all the variables defined so far. To evaluate code one either selects
a portion of code or puts the cursor on a line and hits ctrl-enter. It
feels very interactive.
Thank you for this hint!
If I want to run multiple IO actions in ghci and bind the result to
Post by Miguel Negrao
“variables” that I can use later, is this the best way ?
(engine,r,send) <- do
engine <- MS.new withDefaultSynth
let send a = MS.execute engine $ exec_ a
r <- MS.execute engine rootNode
return (engine, r, send)
In GHCi you could just write
Prelude> engine <- MS.new withDefaultSynth
Prelude> let send a = MS.execute engine $ exec_ a
Prelude> r <- MS.execute engine rootNode
But if you want to bundle all three actions, then your do-block is
certainly the best way.
_______________________________________________
haskell-art mailing list
http://lists.lurk.org/mailman/listinfo/haskell-art
Rohan Drape
2013-01-08 23:20:13 UTC
Permalink
Post by Henning Thielemann
it should be possible to add support for multi-line GHCi evaluation in
emacs — you just need to wrap the lines being sent in :{ and :} (you
can use those commands in ghci to write and run multiline code).
excellent, thanks, i didn't know about that.

added as hsc3-run-layout-block (C-cC-f).

best,
rohan

Miguel Negrao
2013-01-05 00:20:46 UTC
Permalink
Post by Henning Thielemann
In GHCi you could just write
Prelude> engine <- MS.new withDefaultSynth
Prelude> let send a = MS.execute engine $ exec_ a
Prelude> r <- MS.execute engine rootNode
But if you want to bundle all three actions, then your do-block is certainly the best way.
Yes, I know that I can evaluate line by line, but that can get boring pretty fast. When doing interactive evaluation sometimes one wants to evaluate a group of statements and do multiple bindings, so yeah, I guess I have to do it that way then.
Post by Henning Thielemann
And just to note, it should be possible to add support for multi-line GHCi evaluation in emacs — you just need to wrap the lines being sent in :{ and :} (you can use those commands in ghci to write and run multiline code).
The hsc3 mode in emacs also has multiline evaluation, that was not the issue, the issue was evaluating expressions that use the indentation rules (so no { } in do blocks, etc ).

best,
Miguel
http://www.friendlyvirus.org/miguelnegrao/
Renick Bell
2013-01-05 00:37:09 UTC
Permalink
You can do multiline evaluation in ghci with regular indentation
(without internal braces) by preceding and following up your code like
this:

Prelude> :{
Prelude| do putStrLn "first line"
Prelude| putStrLn "second line"
Prelude| :}
first line
second line
Prelude>

I use the tslime plugin in vim and this in my .vimrc to do it all in
one keystroke, but I imagine you could also get emacs to add the
braces for you:

map <F11> :call Send_to_Tmux(":{\n")<CR>vip:normal @g<CR>:call
Send_to_Tmux(":}\n")<CR>k

Best,

Renick

On Sat, Jan 5, 2013 at 9:20 AM, Miguel Negrao
Post by Miguel Negrao
Post by Henning Thielemann
In GHCi you could just write
Prelude> engine <- MS.new withDefaultSynth
Prelude> let send a = MS.execute engine $ exec_ a
Prelude> r <- MS.execute engine rootNode
But if you want to bundle all three actions, then your do-block is certainly the best way.
Yes, I know that I can evaluate line by line, but that can get boring pretty fast. When doing interactive evaluation sometimes one wants to evaluate a group of statements and do multiple bindings, so yeah, I guess I have to do it that way then.
Post by Henning Thielemann
And just to note, it should be possible to add support for multi-line GHCi evaluation in emacs — you just need to wrap the lines being sent in :{ and :} (you can use those commands in ghci to write and run multiline code).
The hsc3 mode in emacs also has multiline evaluation, that was not the issue, the issue was evaluating expressions that use the indentation rules (so no { } in do blocks, etc ).
best,
Miguel
http://www.friendlyvirus.org/miguelnegrao/
_______________________________________________
haskell-art mailing list
http://lists.lurk.org/mailman/listinfo/haskell-art
--
Renick Bell
- http://renickbell.net
- http://twitter.com/renick
- http://the3rd2nd.com
Renick Bell
2013-01-05 00:38:03 UTC
Permalink
Sorry, I didn't read carefully. That's exactly what Luke was explaining...
Post by Renick Bell
You can do multiline evaluation in ghci with regular indentation
(without internal braces) by preceding and following up your code like
Prelude> :{
Prelude| do putStrLn "first line"
Prelude| putStrLn "second line"
Prelude| :}
first line
second line
Prelude>
I use the tslime plugin in vim and this in my .vimrc to do it all in
one keystroke, but I imagine you could also get emacs to add the
Send_to_Tmux(":}\n")<CR>k
Best,
Renick
On Sat, Jan 5, 2013 at 9:20 AM, Miguel Negrao
Post by Miguel Negrao
Post by Henning Thielemann
In GHCi you could just write
Prelude> engine <- MS.new withDefaultSynth
Prelude> let send a = MS.execute engine $ exec_ a
Prelude> r <- MS.execute engine rootNode
But if you want to bundle all three actions, then your do-block is certainly the best way.
Yes, I know that I can evaluate line by line, but that can get boring pretty fast. When doing interactive evaluation sometimes one wants to evaluate a group of statements and do multiple bindings, so yeah, I guess I have to do it that way then.
Post by Henning Thielemann
And just to note, it should be possible to add support for multi-line GHCi evaluation in emacs — you just need to wrap the lines being sent in :{ and :} (you can use those commands in ghci to write and run multiline code).
The hsc3 mode in emacs also has multiline evaluation, that was not the issue, the issue was evaluating expressions that use the indentation rules (so no { } in do blocks, etc ).
best,
Miguel
http://www.friendlyvirus.org/miguelnegrao/
_______________________________________________
haskell-art mailing list
http://lists.lurk.org/mailman/listinfo/haskell-art
--
Renick Bell
- http://renickbell.net
- http://twitter.com/renick
- http://the3rd2nd.com
--
Renick Bell
- http://renickbell.net
- http://twitter.com/renick
- http://the3rd2nd.com
Henning Thielemann
2013-01-05 00:50:41 UTC
Permalink
Post by Renick Bell
You can do multiline evaluation in ghci with regular indentation
(without internal braces) by preceding and following up your code like
Prelude> :{
Prelude| do putStrLn "first line"
Prelude| putStrLn "second line"
Prelude| :}
first line
second line
Prelude>
Cool! I was not aware of this GHCi feature.
Loading...