Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This work 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 any later version.
- class Sequence {
- Timer timer;
- Shred shr;
- StkInstrument instrument;
- dur durations[];
- string name;
- fun string[] strToArray(string input, string tr) {
- string result[3];
- 0 => int i;
- while (input.find(tr) > -1 ) {
- input.find(tr) => int pos;
- input.substring(0, pos) => result[i];
- input.substring(pos + 1) => input;
- i++;
- }
- input => result[i];
- return result;
- }
- fun void playSeq(string seq[], float scale[],
- StkInstrument instr, float mod) {
- while(true) {
- for(int i; i < seq.size(); i++) {
- seq[i] => string content;
- strToArray(content, " ")@=> string line[];
- line[2].toInt() => int len;
- if (len - 1 > timer.currentBar) {
- timer.newBar => now;
- }
- scale[line[1].toInt() - 1] * mod => instr.freq;
- if(line[0] == "n") {
- Math.random2f(.7, 1) => instrument.noteOn;
- } else {
- 1 => instrument.noteOff;
- }
- durations[line[2].toInt()] * mod => now;
- }
- }
- }
- fun void add(string s[], float sk[], StkInstrument in, float m, string n) {
- n => name;
- in @=> instrument;
- spork~ playSeq(s, sk, in, m) @=> shr;
- }
- fun void remove() {
- 1 => instrument.noteOff;
- Machine.remove(shr.id());
- }
- }
- public class SequenceController {
- Sequence sequences[0];
- Timer t;
- dur durations[];
- fun void addSeq(string s[], float scale[], StkInstrument in,
- float m, string name) {
- sequences.size() + 1 => sequences.size;
- new Sequence @=> sequences[sequences.size() - 1];
- t @=> sequences[sequences.size() - 1].timer;
- durations @=> sequences[sequences.size() - 1].durations;
- sequences[sequences.size() - 1].add(s, scale, in, m, name);
- chout <= "add " <= sequences[sequences.size() - 1].name <= "\n";
- }
- fun void removeSeq(int num) {
- Sequence s[sequences.size() - 1];
- chout <= "remove " <= sequences[num].name <= "\n";
- for(int i; i < s.size(); i++) {
- if(i != num) {
- sequences[i] @=> s[i];
- } else {
- sequences[i + 1] @=> s[i];
- }
- }
- sequences[num].remove();
- s @=> sequences;
- }
- fun void lookup() {
- if (sequences.size() > 0) {
- chout <= "\n" <= "current sequences: " <= "\n";
- for(int i; i < sequences.size(); i++) {
- chout <= sequences[i].name <= " - " <= i <= "\n";
- }
- chout <= "\n";
- } else chout <= "no sequences" <= "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement