Skip to content

Commit

Permalink
Demo patchers.
Browse files Browse the repository at this point in the history
  • Loading branch information
cassiel committed Jun 2, 2012
1 parent 30a2118 commit 6eac5c3
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 30 deletions.
28 changes: 26 additions & 2 deletions README.md
Expand Up @@ -14,8 +14,8 @@ The file of patchers and Clojure script files
(`maxmsp-clojure-expo74.zip`) goes into the `patches` folder for
Max (or anywhere in Max's search path).

Downloads available under this GitHub project if you have an account; otherwise, all
available from [Dropbox][dropbox].
Downloads available under this GitHub project if you have an account;
otherwise, all available from [Dropbox][dropbox].

## Java

Expand All @@ -27,12 +27,33 @@ Terminal window prompts to start the installation process.
For Windows, Java is downloadable from [Oracle][java]. The JRE (Java
Runtime) will probably work, but I tested with the JDK.

## Getting Started

The directory `trails` contains README files for a set of tutorials;
corresponding patchers are in the directory `patchers`. The directory
`DONE` contains completed exercises.

More advanced examples can be found in the
source [net.loadbang.clojure][nl-clojure] project.

## Other Software

* Windows text editor: [Notepad++][npp] - supports editing of Lisp source.
* OS X text editor: [TextMate][tm] - supports bracket matching.
* Either platform: [jEdit][jedit] - native Java application.

## Original Sources

All the `net.loadbang` sources are on GitHub:

* [net.loadbang.clojure][nl-clojure]
* [net.loadbang.scripting][nl-scripting]
* [net.loadbang.lib][nl-lib]

The other dependent libraries (`log4j`, and Clojure itself) are pulled
in via Maven in the build process; sources are also available for
these.

## Online Resources

* [Lisp (Wikipedia)][wlisp].
Expand All @@ -47,3 +68,6 @@ Runtime) will probably work, but I tested with the JDK.
[tm]: http://macromates.com
[jedit]: http://www.jedit.org
[dropbox]: http://dl.dropbox.com/u/2546860/expo74-clojure-all.zip
[nl-clojure]: https://github.com/cassiel/net.loadbang.clojure
[nl-scripting]: https://github.com/cassiel/net.loadbang.scripting
[nl-lib]: https://github.com/cassiel/net.loadbang.lib
37 changes: 30 additions & 7 deletions patchers/GRIDSTATE.maxpat
Expand Up @@ -4,10 +4,10 @@
"appversion" : {
"major" : 6,
"minor" : 0,
"revision" : 3
"revision" : 4
}
,
"rect" : [ 25.0, 50.0, 809.0, 793.0 ],
"rect" : [ 43.0, 50.0, 694.0, 793.0 ],
"bglocked" : 0,
"openinpresentation" : 0,
"default_fontsize" : 12.0,
Expand Down Expand Up @@ -54,10 +54,10 @@
"appversion" : {
"major" : 6,
"minor" : 0,
"revision" : 3
"revision" : 4
}
,
"rect" : [ 729.0, 179.0, 396.0, 252.0 ],
"rect" : [ 546.0, 101.0, 558.0, 418.0 ],
"bglocked" : 0,
"openinpresentation" : 0,
"default_fontsize" : 12.0,
Expand All @@ -78,6 +78,20 @@
"tags" : "",
"visible" : 1,
"boxes" : [ {
"box" : {
"fontname" : "Anonymous Pro",
"fontsize" : 12.0,
"id" : "obj-3",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 250.0, 70.0, 56.0, 16.0 ],
"text" : "(clear)"
}

}
, {
"box" : {
"fontname" : "Anonymous Pro",
"fontsize" : 12.0,
Expand Down Expand Up @@ -152,6 +166,15 @@
"source" : [ "obj-2", 0 ]
}

}
, {
"patchline" : {
"destination" : [ "obj-11", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-3", 0 ]
}

}
, {
"patchline" : {
Expand Down Expand Up @@ -252,21 +275,21 @@
],
"dependency_cache" : [ {
"name" : "g64c.Grid.maxpat",
"bootpath" : "/Users/nick/CASSIEL-GIT/maxmsp-clojure-expo74/patchers/patchers",
"bootpath" : "/Users/nick/CASSIEL-GIT/maxmsp-clojure-expo74/patchers",
"patcherrelativepath" : "",
"type" : "JSON",
"implicit" : 1
}
, {
"name" : "g64c.Column.maxpat",
"bootpath" : "/Users/nick/CASSIEL-GIT/maxmsp-clojure-expo74/patchers/patchers",
"bootpath" : "/Users/nick/CASSIEL-GIT/maxmsp-clojure-expo74/patchers",
"patcherrelativepath" : "",
"type" : "JSON",
"implicit" : 1
}
, {
"name" : "g64c.Cell.maxpat",
"bootpath" : "/Users/nick/CASSIEL-GIT/maxmsp-clojure-expo74/patchers/patchers",
"bootpath" : "/Users/nick/CASSIEL-GIT/maxmsp-clojure-expo74/patchers",
"patcherrelativepath" : "",
"type" : "JSON",
"implicit" : 1
Expand Down
112 changes: 103 additions & 9 deletions patchers/INTERACTION.maxpat
Expand Up @@ -4,10 +4,10 @@
"appversion" : {
"major" : 6,
"minor" : 0,
"revision" : 3
"revision" : 4
}
,
"rect" : [ 110.0, 47.0, 694.0, 793.0 ],
"rect" : [ 39.0, 49.0, 694.0, 780.0 ],
"bglocked" : 0,
"openinpresentation" : 0,
"default_fontsize" : 12.0,
Expand Down Expand Up @@ -53,10 +53,10 @@
"appversion" : {
"major" : 6,
"minor" : 0,
"revision" : 3
"revision" : 4
}
,
"rect" : [ 509.0, 86.0, 775.0, 330.0 ],
"rect" : [ -18.0, 55.0, 1118.0, 478.0 ],
"bglocked" : 0,
"openinpresentation" : 0,
"default_fontsize" : 12.0,
Expand All @@ -75,7 +75,65 @@
"description" : "",
"digest" : "",
"tags" : "",
"visible" : 1,
"boxes" : [ {
"box" : {
"fontname" : "Anonymous Pro",
"fontsize" : 12.0,
"id" : "obj-7",
"linecount" : 2,
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 115.0, 155.0, 653.0, 28.0 ],
"text" : "(defn click [cx cy] (fundraw (fn [x y] (or (and (= cx x) ( <= (Math/abs (- cy y )) 2)) (and (= cy y) ( <= (Math/abs (- cx x )) 2))))))"
}

}
, {
"box" : {
"fontname" : "Anonymous Pro",
"fontsize" : 12.0,
"id" : "obj-5",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 125.0, 120.0, 194.0, 16.0 ],
"text" : "(defn hover [hx hy how] nil)"
}

}
, {
"box" : {
"fontname" : "Anonymous Pro",
"fontsize" : 12.0,
"id" : "obj-3",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 95.0, 205.0, 568.0, 16.0 ],
"text" : "(defn click [cx cy] (fundraw (fn [x y] (= (Math/abs (- cx x)) (Math/abs (- cy y))))))"
}

}
, {
"box" : {
"fontname" : "Anonymous Pro",
"fontsize" : 12.0,
"id" : "obj-2",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 45.0, 75.0, 378.0, 16.0 ],
"text" : "(defn hover [hx hy how] ( fundraw (fn [x y] (= hx x ))))"
}

}
, {
"box" : {
"fontname" : "Anonymous Pro",
"fontsize" : 12.0,
Expand All @@ -84,7 +142,7 @@
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 60.0, 130.0, 463.0, 16.0 ],
"patching_rect" : [ 70.0, 95.0, 463.0, 16.0 ],
"text" : "(defn hover [hx hy how] (fundraw (fn [x y] (and (= hx x) (= hy y)))))"
}

Expand All @@ -98,7 +156,7 @@
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 110.0, 60.0, 568.0, 16.0 ],
"patching_rect" : [ 130.0, 25.0, 568.0, 16.0 ],
"text" : "(defn click [cx cy] (fundraw (fn [x y] (if (or (= x cx) (= y cy)) [1 0 0] [0 0 0]))))"
}

Expand All @@ -116,13 +174,40 @@
}
],
"lines" : [ {
"patchline" : {
"destination" : [ "obj-11", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-2", 0 ]
}

}
, {
"patchline" : {
"destination" : [ "obj-11", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-3", 0 ]
}

}
, {
"patchline" : {
"destination" : [ "obj-11", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-4", 0 ]
}

}
, {
"patchline" : {
"destination" : [ "obj-11", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-5", 0 ]
}

}
, {
"patchline" : {
Expand All @@ -132,6 +217,15 @@
"source" : [ "obj-6", 0 ]
}

}
, {
"patchline" : {
"destination" : [ "obj-11", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-7", 0 ]
}

}
],
"dependency_cache" : [ ]
Expand Down Expand Up @@ -223,21 +317,21 @@
],
"dependency_cache" : [ {
"name" : "g64c.Grid.maxpat",
"bootpath" : "/Users/nick/CASSIEL-GIT/maxmsp-clojure-expo74/patchers/patchers",
"bootpath" : "/Users/nick/CASSIEL-GIT/maxmsp-clojure-expo74/patchers",
"patcherrelativepath" : "",
"type" : "JSON",
"implicit" : 1
}
, {
"name" : "g64c.Column.maxpat",
"bootpath" : "/Users/nick/CASSIEL-GIT/maxmsp-clojure-expo74/patchers/patchers",
"bootpath" : "/Users/nick/CASSIEL-GIT/maxmsp-clojure-expo74/patchers",
"patcherrelativepath" : "",
"type" : "JSON",
"implicit" : 1
}
, {
"name" : "g64c.Cell.maxpat",
"bootpath" : "/Users/nick/CASSIEL-GIT/maxmsp-clojure-expo74/patchers/patchers",
"bootpath" : "/Users/nick/CASSIEL-GIT/maxmsp-clojure-expo74/patchers",
"patcherrelativepath" : "",
"type" : "JSON",
"implicit" : 1
Expand Down
10 changes: 9 additions & 1 deletion patchers/set-only.clj
Expand Up @@ -7,5 +7,13 @@
(defn draw [state]
(fundraw (fn [x y] (get state [x y]))))

(defn clear []
(draw (swap! the-state (fn [old] { } ))))

;(defn click [x y]
; (draw (swap! the-state (fn [old] (assoc old [x y] true)))))

(defn click [x y]
(draw (swap! the-state (fn [old] (assoc old [x y] true)))))
(draw (swap! the-state
(fn [old] (assoc (assoc old [x y] true)
[(- 7 x) y] true)))))
23 changes: 12 additions & 11 deletions trails/4-STATE.md
Expand Up @@ -4,25 +4,26 @@ Clojure wants to be purely functional - "variables" cannot be updated.

Updatable variables must be created specially as *atoms*:

(def the-state (atom 0))
(def the-state (atom 0))

Atom values are accessed by *dereferencing*

(deref the-state)
@the-state
(deref the-state)
@the-state

An atom's value is changed by applying a function to its old value:

(swap! the-state (fn [x] (* x 2)))
(swap! the-state inc)
(swap! the-state (fn [x] (* x 2)))
(swap! the-state inc)

This is done as a *transaction*.

An atom can contain a complex data structure - and an update function can partially alter it.
An atom can contain a complex data structure - and an update function
can partially alter it.

(def the-state (atom []))
(def the-state (atom []))

(swap! the-state (fn [x] (conj x 2)))
(swap! the-state (fn [x] (conj x (rand))))
(swap! the-state pop)
(swap! the-state (fn [x] (vec (map inc x))))
(swap! the-state (fn [x] (conj x 2)))
(swap! the-state (fn [x] (conj x (rand))))
(swap! the-state pop)
(swap! the-state (fn [x] (vec (map inc x))))

0 comments on commit 6eac5c3

Please sign in to comment.