Permalink
Cannot retrieve contributors at this time
| # Bubblesort - Celltone example | |
| # Two parts with 32 note positions each are sorted using a | |
| # version of bubblesort. Initially both parts are reversed. | |
| # melody | |
| a = [26, 24, 22, 20, 19, 17, 15, 14, 12, 10, 8, 7, 5, 3, 2, 0, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _] | |
| b = [_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 2, 3, 5, 7, 8, 10, 12, 14, 15, 17, 19, 20, 22, 24, 26, 27] | |
| a.octava = 5 | |
| b.octava = 5 | |
| b.channel = 1 | |
| # guards | |
| # since celltone reads parts in a cyclic fashion, it has no inherent knowledge of | |
| # boundaries. that's why we need to have a muted part with a note at the start and | |
| # a note at the end. without the guards, notes would be swapped at the boundaries, | |
| # and the sort would never succeed. | |
| x = [0, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 1] | |
| x.velocity = 0 | |
| # this is where the actual sorting happens. note that _ (pause) is defined to be | |
| # less than any note. | |
| {x[0] != 0, x[-1] != 1, a[-1] > a[0]} => {a[-1] = a[0], a[0] = a[-1]} # ascending | |
| {x[0] != 0, x[-1] != 1, b[-1] < b[0]} => {b[-1] = b[0], b[0] = b[-1]} # descending |