denemo-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Denemo-devel] Scripts and Questions


From: Richard Shann
Subject: Re: [Denemo-devel] Scripts and Questions
Date: Wed, 15 Jul 2009 10:00:02 +0100

On Wed, 2009-07-15 at 00:38 +0200, Nils Gey wrote:
> Hi people,
> 
> my first real and useful (for me :)) script.
I too am just learning scheme - I want to make some suggestions, please
don't be discouraged if I make a lot of them.

Firstly, the script defines global variables: this means that if another
script uses the same name for something else obscure bugs will arise.
My solution to this is: Always enclose a script like this in a (let ...)
like this:
        (let ((GoUp #f) (...) ...)
            your script
        )

This makes GoUp an internal variable, not defined at the top level. Its
initial value is #f but you are going to define it as a procedure a few
lines later, before it is ever used. You can (should) then use (set!
GoUp ....) rather than (define GoUp ....) because this will fail if you
have forgotten to define it, which will prevent you accidentally
defining a global variable.
I have a convention for defining global variables (see init.scm in
Transpose).

Second general point: you use "interval" as a global variable instead of
passing it as a parameter. That's not so good. See my inline suggestion
below.

Lastly, your script makes a couple of definitions then asks the user for
a keypress setting interval,  then makes another definition then runs
the AddInterval function that uses the value interval gotten from the
user. Instead, define all your procedures and then at the end put the
steps your script should take using them.

> 
> Its not complete and I have a few question.
> Of course this can be simplified, but it growed as I wrote it, optimizing 
> comes last.
> 
> ;;Add Interval on top. User can choose.
> ;;This uses the traditional diatonic system. 1 = Prime, 3 = Third....
> 
> (define (GoUp x x-max dx) ; Define CursorUp Loop. actually stolen from some 
> website
>    (if (<= x x-max)
>       (begin
>               (d-CursorUp)
>         (GoUp (+ x dx) x-max dx))))
> 
> (define (GoDown x x-max dx) ; same for CursorDown
>    (if (<= x x-max)
>       (begin
>          (d-CursorDown)
>          (GoDown (+ x dx) x-max dx))))
> 
> (define interval (d-GetKeypress)); Does not test if its only a number or 
> anything.

Move this line further down....
> 
> (define AddInterval 
>   (lambda ()
>     (begin
>       (GoUp 2 (string->number interval) 1) ;starts with 2 so Prime=1
>       (d-AddNoteToChord)
>       (GoDown 2 (string->number interval)1) 
>       )))
> 

.... to here. Better still start a ((let interval 0)... here
then (set! interval (d-GetKeypress))
        (AddInterval interval)
);;finish the (let ...)

> (AddInterval) ; Go!
> 
> ;End of Script
> 
> 
> And now the questions
> 
> 1) Is there some hidden scheme-output besides the console? All tutorials and 
> scheme-manuals say if you just write values they will be returned to the 
> standard-output.
> 
yes - the script output is just really debug chatter which I have never
turned off. Nothing to do with scheme, just a print statement I put in.
> Instead the bash-terminal gets spammed with all code, including comments and 
> whitespace/empty lines. Maybe this can be redirected and stripped to a new 
> tab in the console frame? 
> 
> Makes it maybe easier to look for real things in the console.
> 
> 2) Is there a schemeway to construct already existing (denemo)-commands with 
> variables? Like
> (d-2) adds a quarter note in classic mode. But I want to exchange the "2" 
> with another value. A clumsy way would be to make a huge "case". But with 
> something like a preprocessor this would be easier.
> 
Yes, I have done a little bit of that, you do 

(string-append "d-" number)

and then some tricky stuff to make it execute the command whose name is
that string.


> 3) What is the command to jump to the (next) note on the same cursorposition, 
> means vertical. In my script the cursor just goes up and down from its 
> current position, but I want that the chordnotes are added relative to the 
> lowest note.
> 
You mean move the cursor upwards until it is on the next higher note in
a multi-note chord?

This is a difficulty which Jeremiah is tackling at the moment.


> 4) How does ApplyToSelection work? I tried to look at the transpose script 
> for selections, but this is also broken.

It seems to be not working

The script is



(let ((command 0))
        (begin
(set! command (d-GetCommand))
(if (string=? command "d-")
    (d-WarningDialog "This keypress is not a shortcut") 
    (begin
      (set! command (string-append "(" command ")"))    
      (ApplyToSelection command "(d-GoToMark)")))))


which is using this tricky business I mentioned earlier of creating the
name of a command. there is a procedure ApplyToSelection here which must
be in denemo.scm, yes it is

(define ApplyToSelection (lambda (command positioning_command)
                           (begin
                             (if (eval-string positioning_command)
                                 (begin
                                    (eval-string  command)
                                    (ApplyToSelection command 
"(d-NextSelectedObject)"))))))

so it should be going through each selected object applying the command.
But trying it with keypress "period" I just get the last note dotted.
When it broke I don't know...

> 
> Btw. how do you think Selections and commands should work? In my opinion a 
> command like ApplyToSelection shouldn't be necessary for standard tasks. Any 
> single/@cursor command should work on a complete selection without the need 
> for a special "for selection" script.
> 
?What? So delete would delete the selection if there was one. Well, you
could always define a set of shortcuts thus...

Last point, I think it would be good to standardise and either always
use or never use the lambda notation. I vote for never use, (define
(proc..)) is, in the end, just easier to read once you know the
notation.

Richard

> I know selecting is not very well at the moment, but maybe someday this will 
> be redesigned? (I hope).
> 
> 
> Greetings,
> 
> Nils
> 
> 
> _______________________________________________
> Denemo-devel mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/denemo-devel





reply via email to

[Prev in Thread] Current Thread [Next in Thread]