diff options
author | Thomas White <taw@physics.org> | 2022-11-12 11:13:53 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2022-11-12 11:37:03 +0100 |
commit | 5a02170f9e1952cd335b6b097e8ce33de7bb35b1 (patch) | |
tree | ca21feda4181e444e10e11ce863cc017c69461e7 /guile/starlet/attributes.scm | |
parent | f99311300912814ccaf4fdd6b3c753d1206e024c (diff) |
Introduce new type for attribute names
There's a serious problem with the design so far, where symbols are used
for attribute names (intensity, strobe, colour etc), and also for
attribute values (on, off, random etc). There's no way for 'at' to
tell the difference between the two. For example, this form is
ambiguous: (at myfixture 'strobe 'on)
This commit introduces a new class, <starlet-attribute>, to replace the
use of symbols here. The attributes are enumerated in (starlet attributes),
and new ones can be added later. The attribute objects remember their
'canonical' names, to allow states to be printed.
Apart from solving the ambiguity problem, this has two further
advantages. First, attribute names no longer need to be quoted
everywhere. Second, multiple names can be used to refer to the same
attribute. For example: (define color colour).
Diffstat (limited to 'guile/starlet/attributes.scm')
-rw-r--r-- | guile/starlet/attributes.scm | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/guile/starlet/attributes.scm b/guile/starlet/attributes.scm new file mode 100644 index 0000000..7d2a561 --- /dev/null +++ b/guile/starlet/attributes.scm @@ -0,0 +1,82 @@ +;; +;; starlet/attributes.scm +;; +;; Copyright © 2022 Thomas White <taw@bitwiz.org.uk> +;; +;; This file is part of Starlet. +;; +;; Starlet is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <http://www.gnu.org/licenses/>. +;; +(define-module (starlet attributes) + #:use-module (oop goops) + #:export (<starlet-attribute> + make-attribute + attribute? + intensity? + canonical-name)) + + +(define-class <starlet-attribute> (<object>) + (canonical-name + #:init-keyword #:name + #:getter canonical-name)) + +(define (make-attribute canonical-name) + (make <starlet-attribute> + #:name canonical-name)) + +(define (attribute? a) + (is-a? a <starlet-attribute>)) + +(define-method (write (attribute <starlet-attribute>) port) + (write + (canonical-name attribute) + port)) + +(define-method (canonical-name whatever) + whatever) + + +;; The standard attribute names +;; Note that this list says nothing about the interpretation of the values +;; - that's left to the individual fixture definitions. +(define-public intensity (make-attribute 'intensity)) +(define-public colour (make-attribute 'colour)) +(define-public colour-temperature (make-attribute 'colour-temperature)) +(define-public strobe (make-attribute 'strobe)) +(define-public strobe-frequency (make-attribute 'strobe-frequency)) +(define-public pan (make-attribute 'pan)) +(define-public tilt (make-attribute 'tilt)) +(define-public prism (make-attribute 'prism)) +(define-public frost (make-attribute 'frost)) +(define-public hotspot (make-attribute 'hotspot)) +(define-public iris (make-attribute 'iris)) +(define-public zoom (make-attribute 'zoom)) +(define-public barndoor-rotation (make-attribute 'barndoor-rotation)) +(define-public barndoor1 (make-attribute 'barndoor1)) +(define-public barndoor2 (make-attribute 'barndoor2)) +(define-public barndoor3 (make-attribute 'barndoor3)) +(define-public barndoor4 (make-attribute 'barndoor4)) +(define-public beamtype (make-attribute 'beamtype)) +(define-public colwheel (make-attribute 'colwheel)) +(define-public gobo (make-attribute 'gobo)) + +;; Duplicate names for convenience... +(define-public color colour) +(define-public color-temperature colour-temperature) + + +(define (intensity? a) + (eq? intensity a)) + |