File: start-end.patch.tcl

package info (click to toggle)
din 5.2.1-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 2,200 kB
  • sloc: cpp: 9,369; sh: 6,563; ansic: 2,977; tcl: 1,770; makefile: 283
file content (110 lines) | stat: -rw-r--r-- 3,056 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
if {0} {

  /*
   * This file is part of din.
   *
   * din is copyright (c) 2006 - 2012 S Jagannathan <jag@dinisnoise.org>
   * For more information, please visit http://dinisnoise.org
   *
   * din 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 2 of the License, or
   * (at your option) any later version.
   *
   * din 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 din.  If not, see <http://www.gnu.org/licenses/>.
   *
  */

  for each assigned midi #cc, go from a start value to an end value
  executing a command for each inbetween value

  can be used to:

    set AM and FM depth
    set bpm
    set drone master volume
    set key & more

  examples:

    assign ;# no arguments -> just print current assignments

    ;# assign MIDI #CC ie slider/knob 1 to go from current key to an octave above
    assign 1 [key value] [expr $8 * [key value]] key

    ;# assign MIDI #CC 2 to go from current key to 2 octaves above
    assign 2 [key value] [expr $8 * $8 * [key value]] key

    ;# assign MIDI #CC 3 to go from current key to perfect-fourth an octave above
    assign 3 [key value] [expr $8 * $4 * [key value]] key

    ;# assign MIDI #CC 4 to go from BPM of gater-l to 4 times BPM of gater-l
    assign 4 [get-bpm gl] [expr 4 * [get-bpm gl]] {set-bpm {gl gr}}

    8 and 4 are built in interval variables in din ($8 & $4 are their
    values -> see TCL documentation).

    ;# must use {} to separate & include words properly.
    ;# see TCL documentation

    assign 5 0 100 set-var fm_depth ;# wrong :(

    ;# assign MIDI #CC 5 to set fm_depth variable from 0 to 100.
    assign 5 0 100 {set-var fm_depth} ;# right :)

    ;# retain start/end as above ie 0 & 100 but change command to set-bpm {gl gr}
    assign 5 . . {set-bpm {gl gr}}

}

proc assign {{cc ""} {startt .} {endd .} {cmdd .}} {

  global start end cmd

  if {$cc eq ""} {
    ;# print all assignments
    foreach i [lsort [array names start]] {
      echo "#cc: $i, start: $start($i), end: $end($i), command: $cmd($i)"
    }
    return
  }

  if {$startt ne "."} {
    ;# set start
    set start($cc) $startt
  }

  if {$endd ne "."} {
    ;# set end
    set end($cc) $endd
  }

  if {$cmdd ne "."} {
    ;# set command
    set cmd($cc) $cmdd
  }

}

proc exists {cc} {
  ;# does cc exist ie has cc got an assignment?
  global start
  lsearch [array names start] $cc
}

proc midi-cc {status cc value} {
  global start end cmd
  if {[exists $cc] > -1} {
    set s $start($cc) ;# get start
    set e $end($cc) ;# get end
    set c $cmd($cc) ;# get command
    ;# execute command with interpolated value as only argument
    eval "$c [get-val $s $e $value]"
  }
}