Skip to content

Commit

Permalink
Major fix/update for lib/permutation.dc; fix for midi_change_ring.dc …
Browse files Browse the repository at this point in the history
…example; add a simpler midi_change_ring.dc example
  • Loading branch information
Aaron K. Johnson committed Mar 7, 2024
1 parent 9000755 commit 9562b24
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 155 deletions.
18 changes: 11 additions & 7 deletions examples/kaleidoscope.dc
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# run this in an 80x24 terminal
#
# use: nice -19 dclang kaleidoscope
# usage: nice -19 dclang kaleidoscope.dc

# buffer size is 1921 (1920, but 1 extra slot for null character)
var mybuf
80 24 * 1 + mkbuf
1921 mkbuf
mybuf !

# characters to choose from, right now, set to ' ' and '*'
32 1 !
42 2 !
32 3 !
Expand All @@ -16,20 +18,22 @@ mybuf !

: kaleidoscope
4096 times
0
0 # buffer offset, local on the stack
24 times
80 times
i 160 / 0.25 - dup * # This is all distance formula stuff:
j 48 / 0.25 - dup * # sqrt(a^2 + b^2)...distance from origin
+ sqrt sin # (sine of the distance from origin)
+ sqrt sin # (sine of the distance from origin)
k 0.5 * * cos 0.5 * 0.51 + 2.9 * floor
1 + @ bufadd
1 +
1 + # increment the buffer offset
again
again
mybuf @ 80 24 * + 0 1 memset drop
# add null char on buffer end
mybuf @ 1920 + 0 1 memset drop
# print the buffer
mybuf @ print
0.045 sleep
0.04 sleep
drop
again
;
Expand Down
12 changes: 4 additions & 8 deletions examples/midi_change_ring.dc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
"redis_midi.dc" import
"permutations.dc" import

var perm_space
6 setup_permutation_space
perm_space !
var perm_obj
6 setup_permutation
perm_obj !

create oct_perm_space 3 , 0 , 1 , 2 , -1 , 0 , 0 , 0 ,
create lengths 1 , 1 , 1 , 2 , 2 ,
var len_idx
0 len_idx !
Expand Down Expand Up @@ -45,13 +44,10 @@ create scale 0 , 9_8 , 7_6 , 3_2 , 7_4 , 9_4 ,
###
100
scale
perm_space @ next_permutation
perm_obj @ next_permutation_item
+
@
redis_midi.get_transpose
+
oct_perm_space next_permutation
midi_edo @ *
+
dup svpush
0
Expand Down
39 changes: 39 additions & 0 deletions examples/midi_change_ring_simple.dc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"midi.dc" import
"redis_midi.dc" import
"permutations.dc" import

var perm_obj
6 setup_permutation
perm_obj !

create scale 60 , 62 , 65 , 67 , 70 , 72 ,
-7 const TRANSPOSITION

: _midi_change_ring
block_sigint
###
100
scale
perm_obj @ next_permutation_item
+
@
TRANSPOSITION +
dup svpush
0x90
send_midi_reverse
###
redis_midi.get_on_gate sleep
0 svpop 0x90 send_midi_reverse
redis_midi.get_off_gate sleep
unblock_sigint
_midi_change_ring
;

: midi_change_ring
"You are now entering an endless loop, hit CTRL-C to stop..." print cr
"Notice that you won't be able to stop until a note off event hits." print cr
"In this way, the notes end cleanly!" print cr
_midi_change_ring
;

midi_change_ring
14 changes: 5 additions & 9 deletions examples/permutation_example.dc
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
"permutations.dc" import

var perm_space
5 setup_permutation_space
perm_space !
var perm_obj
5 setup_permutation
perm_obj !

: run_through_permutations
"Here are the 120 permutations of 5 items!" print cr
120 5 * times
perm_space @ next_permutation .
i 5 % 4 =
if
cr
endif
120 times
perm_obj @ print_next_permutation
again
;

Expand Down
2 changes: 2 additions & 0 deletions lib/math.dc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"digit_sum: need <number> and <base> on the stack!" const :DIGIT_SUM_ERROR

: isneg 1 swap / 0 < ;

: absmod
dup svpush
%
Expand Down
Loading

0 comments on commit 9562b24

Please sign in to comment.