3

我刚刚开始使用 Overtone,但我想从一开始就让事情有条理。

project.clj:

(defproject overtone-sketchbook "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.5.1"]
                 [overtone "0.9.1"]])

src/overtone_sketchbook/synths.clj:

(ns overtone-sketchbook.synths
  (:use [overtone.live]))

(definst pluck-saw [f 800 d 3]
         (* (saw (+ 100 (* 200 (saw d))))
            (pluck (* (white-noise)
                      (env-gen (perc 0.001 2) :action FREE))
                   1 3 (/ 1 f))))

REPL 会话 1:

> lein repl
nREPL server started on port 52425
REPL-y 0.2.0
Clojure 1.5.1
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)

user=> (use 'overtone.live)
--> Loading Overtone...
  ********************************************************** 
       WARNING: JVM argument TieredStopAtLevel=1 is active, and may 
       lead to reduced performance. This happens to currently be the 
       default lein setting:

       https://github.com/technomancy/leiningen/pull/1230

       If you didn't intend this JVM arg to be specified, you can turn 
       it off in your project.clj file or your global 
       ~/.lein/profiles.clj file by adding the key-val

       :jvm-opts ^:replace [] 
       ********************************************************** 
--> Booting internal SuperCollider server...
Found 0 LADSPA plugins
*** ERROR: open directory failed '/Users/ilya/Library/Application Support/SuperCollider/synthdefs'
Number of Devices: 2
   0 : "Built-in Input"
   1 : "Built-in Output"

"Built-in Input" Input Device
   Streams: 1
      0  channels 2

"Built-in Output" Output Device
   Streams: 1
      0  channels 2

SC_AudioDriver: sample rate = 44100.000000, driver's block size = 512
--> Connecting to internal SuperCollider server...
--> Connection established

    _____                 __
   / __  /_  _____  _____/ /_____  ____  ___
  / / / / | / / _ \/ ___/ __/ __ \/ __ \/ _ \
 / /_/ /| |/ /  __/ /  / /_/ /_/ / / / /  __/
 \____/ |___/\___/_/   \__/\____/_/ /_/\___/

   Collaborative Programmable Music. v0.9.1


Hey Ilya, I feel something magical is only just beyond the horizon...

nil
user=> (demo overtone-sketchbook.synths/pluck-saw)

IllegalArgumentException Don't know how to create ISeq from: clojure.lang.Symbol  clojure.lang.RT.seqFrom (RT.java:505)
user=> (use 'overtone-sketchbook.synths)
nil
user=> (demo overtone-sketchbook.synths/pluck-saw)

IllegalArgumentException Don't know how to create ISeq from: clojure.lang.Symbol  clojure.lang.RT.seqFrom (RT.java:505)
user=> (demo pluck-saw)

IllegalArgumentException Don't know how to create ISeq from: clojure.lang.Symbol  clojure.lang.RT.seqFrom (RT.java:505)
user=> (require 'overtone-sketchbook.synths)
nil
user=> (demo pluck-saw)

IllegalArgumentException Don't know how to create ISeq from: clojure.lang.Symbol  clojure.lang.RT.seqFrom (RT.java:505)
user=> (demo overtone-sketchbook.synths/pluck-saw)

IllegalArgumentException Don't know how to create ISeq from: clojure.lang.Symbol  clojure.lang.RT.seqFrom (RT.java:505)
user=> Bye for now!

REPL 会话 2:

> lein repl
nREPL server started on port 52100
REPL-y 0.2.0
Clojure 1.5.1
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)

user=> (use 'overtone-sketchbook.synths)
--> Loading Overtone...
  ********************************************************** 
       WARNING: JVM argument TieredStopAtLevel=1 is active, and may 
       lead to reduced performance. This happens to currently be the 
       default lein setting:

       https://github.com/technomancy/leiningen/pull/1230

       If you didn't intend this JVM arg to be specified, you can turn 
       it off in your project.clj file or your global 
       ~/.lein/profiles.clj file by adding the key-val

       :jvm-opts ^:replace [] 
       ********************************************************** 
--> Booting internal SuperCollider server...
Found 0 LADSPA plugins
*** ERROR: open directory failed '/Users/ilya/Library/Application Support/SuperCollider/synthdefs'
Number of Devices: 2
   0 : "Built-in Input"
   1 : "Built-in Output"

"Built-in Input" Input Device
   Streams: 1
      0  channels 2

"Built-in Output" Output Device
   Streams: 1
      0  channels 2

SC_AudioDriver: sample rate = 44100.000000, driver's block size = 512
--> Connecting to internal SuperCollider server...
--> Connection established

    _____                 __
   / __  /_  _____  _____/ /_____  ____  ___
  / / / / | / / _ \/ ___/ __/ __ \/ __ \/ _ \
 / /_/ /| |/ /  __/ /  / /_/ /_/ / / / /  __/
 \____/ |___/\___/_/   \__/\____/_/ /_/\___/

   Collaborative Programmable Music. v0.9.1


Hello Ilya, may algorithmic beauty pour forth from your fingertips today.

nil
user=> pluck-saw
#overtone.studio.inst.Inst{:name "pluck-saw", :params ({:value #<Atom@24fc9cde: 800.0>, :name "f", :default 800.0, :rate :kr} {:value #<Atom@449ec5ca: 3.0>, :name "d", :default 3.0, :rate :kr}), :args ("f" "d"), :sdef {:name "overtone-sketchboo96d/pluck-saw", :constants [0.0 0 2.0 3.0 0.5 1.0 50.0 100.0 200.0 1 2 -99 -4 5 0.001], :params (800.0 3.0), :pnames ({:name "f", :index 0} {:name "d", :index 1}), :ugens ({:n-inputs 0, :args nil, :outputs ({:rate 1} {:rate 1}), :name "Control", :rate 1, :n-outputs 2, :rate-name :kr, :inputs (), :special 0, :id 280} #<sc-ugen: saw:ar [1]> #<sc-ugen: binary-op-u-gen:ar [2]> #<sc-ugen: binary-op-u-gen:ar [3]> #<sc-ugen: saw:ar [4]> #<sc-ugen: white-noise:ar [0]> #<sc-ugen: env-gen:kr [0]> #<sc-ugen: binary-op-u-gen:ar [2]> #<sc-ugen: binary-op-u-gen:kr [1]> #<sc-ugen: pluck:ar [5]> #<sc-ugen: binary-op-u-gen:ar [11]> #<sc-ugen: out:ar [12]>)}, :group #<synth-group[live]: Inst pluck-saw Container 31>, :instance-group #<synth-group[live]: Inst pluck-saw 32>, :fx-group #<synth-group[live]: Inst pluck-saw FX 33>, :mixer #<synth-node[live]: overtone.stu547/mono-inst-mixer 34>, :bus #<audio-bus: No Name, mono, id 50>, :fx-chain [], :volume #<Atom@6e9cebcc: 1.0>, :pan #<Atom@3cd6d0: 0.0>, :n-chans 1}
user=> (demo pluck-saw)

CompilerException java.lang.RuntimeException: Unable to resolve symbol: demo in this context, compiling:(NO_SOURCE_PATH:1:1) 
user=> (overtone.live/demo pluck-saw)

IllegalArgumentException Don't know how to create ISeq from: clojure.lang.Symbol  clojure.lang.RT.seqFrom (RT.java:505)
user=> Bye for now!

我错过了一些非常基本的东西吗?

4

2 回答 2

10

首先,如果您可以使您的问题更加简单明了,以便轻松识别可能的解决方案,那将有很大帮助。

另外,感谢您尝试使用 Overtone - 抱歉,事情还没有立即清楚。这里发生了很多事情,所以希望在途中问几个问题 :-)

但是,看看你的两个 REPL 摘录,很明显你还没有完全理解三件事:

  • Overtone 如何使用 Clojure 的命名空间
  • 合成器是如何设计的
  • 如何触发合成器

让我简要讨论其中的每一个,希望它们能对正在发生的事情有所了解。

首先,Overtone 对 Clojure 命名空间的使用。Overtone正在use overtone.live做的是将所有 Overtone 的公共 API 函数导入到您当前的命名空间中。这意味着一旦此操作完成,您将可以使用所有公共 API - 即demo,defsynthsin-osc

在您的第二个 REPL 示例中,您尝试做的第一件事是:(demo overtone-sketchbook.synths/pluck-saw)这不起作用,因为 Clojure 还不知道demo您的 namespace 是什么,也没有任何想法overtone-sketchbook.synth。要让它知道这些,你需要use或者require命名空间。有关更多信息,请阅读 Clojure 的ns宏。

其次,Overtone 的合成器是通过调用代表合成器部分的函数(称为 ugens)来设计的。ugen 的例子是saw, sin-osc, lpf. 您可以在 Overtone 备忘单中查看可用 ugens 的完整列表:https ://github.com/overtone/overtone/raw/master/docs/cheatsheet/overtone-cheat-sheet.pdf

demo是一个允许你传入(部分)synthdef 并播放它的宏:

  • (demo (sin-osc))
  • (demo (sin-osc 440))

请注意,ugen 是函数,以便允许您传递参数以修改其行为(例如sin-oscugen 的 440 hz 参数)。

同样重要的是要注意 ugens 不能(当前)被视为与合成器相同。ugen 是合成器的一个组件,合成器是 ugen 的树。这将我引向第三个问题-您正在尝试demo合成pluck-saw器。这是一个已经设计好的合成器,只能被触发。要触发合成器,只需将其作为函数调用:

(pluck-saw)

您还可以将参数(如果设计允许)传递给合成器触发功能。

所以总结一下:

  • 使用 Clojure 的ns宏加载外部命名空间,并拉入函数以使它们可用。对于 Overtone 的默认 API,您需要拉入overtone.liveovertone.core(如果尚未启动服务器,则首先启动服务器)。
  • 合成器是 ugens 的树。Ugens 是标准的 Clojure 函数并返回由宏demodefsynth. 您可以将参数传递给 ugen 函数以指定它们的行为。
  • 合成器不是 ugens。调用 ugen 函数会返回一个可用于合成器设计的数据结构。将合成器作为函数调用会触发(即播放)该合成器。

最后,请加入我们的邮件列表 - 我们很想看看您正在使用 Overtone 做什么(和计划做什么)并与您分享我们的热情:

http://groups.google.com/group/overtone/

于 2014-01-02T10:46:05.973 回答
1

尝试:(demo 'overtone-sketchbook.synths/pluck-saw)

我的代码仍然有错误,我不明白,但这会让你走得更远。

于 2013-12-31T20:19:53.503 回答