File: liveCoder.hpp

package info (click to toggle)
csound 1%3A6.18.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 62,416 kB
  • sloc: ansic: 192,636; cpp: 14,151; javascript: 9,654; objc: 9,181; java: 3,337; python: 3,333; sh: 1,783; yacc: 1,255; xml: 985; perl: 635; lisp: 411; tcl: 341; lex: 217; makefile: 126
file content (91 lines) | stat: -rw-r--r-- 1,817 bytes parent folder | download | duplicates (7)
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
/*
 * live coding demo for Csound 6
 * Author: Rory Walsh 2013
 */ 

#ifndef LIVE_CODER
#define LIVE_CODER

#include <string>
#include <cstdio>
#include "csound.hpp"
#include <iostream>

using namespace std;

/*
 * sub-class Csound 
 */

class liveCsound: public Csound {
public:
  liveCsound(): Csound(), 
		perf_status(0),
		orchestraHistory(""),
		scoreHistory(""),
		channelsHistory(""){
    CompileOrc("nchnls=2");
  }

  ~liveCsound(){}

  //live code session
  int runLiveCodeSession()
  {
    string str;
    unsigned findString;
    char ch;
    while(ch = getchar()){
      str.push_back(ch);
      if(string::npos != str.find("uorc")){
	unsigned strPos = str.find("uorc");
	string orch = str.substr(0, strPos);
	orchestraHistory +=orch;
	csoundCompileOrc(GetCsound(), orch.c_str());
	return 1;
      }		
      else if(string::npos != str.find("usco")){
	unsigned strPos = str.find("usco");
	string score = str.substr(0, strPos);
	csoundReadScore(GetCsound(),(char *)score.c_str());
	return 1;
      }
      else if(string::npos != str.find("uchan")){
	unsigned strPos = str.find("uchan");
	string channel;
	channel.append("event_i \"i\", 999, 0, .1 \n instr 999");
	channel.append(str.substr(0, strPos));
	channel.append("endin\n");
	cout << channel;
	csoundCompileOrc(GetCsound(), channel.c_str());
	return 1;
      }
      else if(string::npos != str.find("orchist")){
	cout << orchestraHistory;
	return 1;
      }
      else if(string::npos != str.find("scohist")){
	cout << scoreHistory;
	return 1;
      }
      else if(string::npos != str.find("ends")){
	cout << "ending live coding session\n";
	return 0;
      }			
			
			
    }
    return 0;
  }

  int result;
  int perf_status;
  string orchestraHistory;
  string scoreHistory;
  string channelsHistory;

private:		
  Csound* csound;
};

#endif