Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Opening this project back up.

  • Loading branch information...
commit 4bc641d438bda90f5edcc8e2fb7411d590288fea 1 parent 2757953
@jacobjoaquin authored
View
53 build/lib/csd/__init__.py
@@ -19,6 +19,12 @@
import re
+def __create_pattern(tag_name):
+ '''Generates a regular expression string for pulling data from
+ inbetween markup tags.'''
+
+ return '<' + tag_name + '>.*?\n(.*)<\/' + tag_name + '>'
+
def get_base64(csd):
'''Not implemented.'''
@@ -29,6 +35,11 @@ def get_csound(csd):
pass
+def get_license(csd):
+ '''Not implemented.'''
+
+ pass
+
def get_midi_base64(csd):
'''Not implemented.'''
@@ -40,27 +51,20 @@ def get_options(csd):
pass
def get_orchestra(csd):
- '''Not implemented.'''
-
- pass
+ '''Returns the orchestra from a Csound CSD.'''
+
+ p = re.compile(__create_pattern('CsInstruments'), re.DOTALL)
+ return ''.join(p.findall(csd))
def get_sample_base64(csd):
'''Not implemented.'''
pass
-
+
def get_score(csd):
- '''Pulls score data from inbetween the <CsScore> markup tags in a
- Csound csd.
-
- .. note:: This should really reside somewhere else, such as a
- csdparse module.
+ '''Returns the score from a Csound CSD.'''
- .. note:: There is an issue with an extra leading and extra
- trailing newline being introduced.
- '''
-
- p = re.compile('<CsScore>(.*)<\/CsScore>', re.DOTALL)
+ p = re.compile(__create_pattern('CsScore'), re.DOTALL)
return ''.join(p.findall(csd))
def get_version(csd):
@@ -68,12 +72,21 @@ def get_version(csd):
pass
-def get_license(csd):
- '''Not implemented.'''
+def overwrite_score(csd, sco):
+ '''Returns a new csd string with a new score.'''
+
+ pre = re.compile('(.*<CsScore>.*?\n)', re.DOTALL)
+ post = re.compile(r'(</CsScore>.*)', re.DOTALL)
+
+ output = []
+ output.append(''.join(pre.findall(csd)))
+ output.append(sco)
- pass
+ # Insist a newline between sco and closing CsScore tag exists
+ if not sco.endswith('\n'):
+ output.append('\n')
+
+ output.append(''.join(post.findall(csd)))
-def replace_score(csd, sco):
- '''Not implemented.'''
+ return ''.join(output)
- pass
View
3  build/lib/csd/sco/__init__.py
@@ -71,8 +71,9 @@ def merge(score, selection):
for k, v in selection.items():
s_list[k] = '\n'.join(__flatten_list(v))
- # Appends an empty event in case of newline
output = '\n'.join(s_list)
+
+ # Appends an empty event in case of newline
if score.endswith('\n'):
output = output + '\n'
View
18 csd/sco/preprocessor/__init__.py
@@ -19,7 +19,6 @@
from csd.sco import event
from csd.sco import element
-#from csd.sco import selection
def carry_to_value(score):
'''Not implemented.'''
@@ -47,18 +46,17 @@ def value_to_carry(score):
# statements only substitute for pfields 3 or higher.
PFIELD_3 = 3
- size = 0
-
# Excluded element token types
elements = [element.EXPRESSION, element.MACRO, element.NO_CARRY];
for e in event_list:
if event.match(e, {0: 'i', 1: last_identifier}):
- lv = len(last_values)
-
- for i in range(PFIELD_3, max(event.number_of_pfields(e), lv)):
+ lolv = len(last_values)
+
+ for i in range(PFIELD_3, max(event.number_of_pfields(e), lolv)):
this_pfield = event.get(e, i)
+ # Detect NO_CARRY
if element.token_type(this_pfield) == element.NO_CARRY:
last_values[i] = this_pfield
break
@@ -66,15 +64,13 @@ def value_to_carry(score):
elif element.token_type(last_values[i]) == element.NO_CARRY:
break
+ # Replace pfield with carry
elif (this_pfield == last_values[i] and
- element.token_type(this_pfield) not in elements):
-
- # Replace pfield with carry
+ element.token_type(this_pfield) not in elements):
e = event.set(e, i, '.')
+ # Add a carry if one does not exist
elif this_pfield == None:
-
- # Add a carry if one does not exist
e = event.push(e, '.')
else:
View
42 demo/carry.py
@@ -57,49 +57,15 @@
import sys
-import csd.sco.event as event
-
-def replace(score):
- '''Replaces subsequent repeated values with a carry (.)'''
-
- event_list = score.splitlines(True)
- last_identifier = None
- last_values = []
- output = []
-
- # Explicitly state pfield 3 instead a magic number. Carry
- # statements only substitute for pfields 3 or higher.
- pfield_3 = 3
-
- for e in event_list:
- if event.match(e, {0: 'i', 1: last_identifier}):
- for i in range(pfield_3, event.number_of_pfields(e)):
- if event.match(e, {i: last_values[i]}):
- e = event.set(e, i, '.')
-
- else:
- last_values[i] = event.get(e, i)
-
- output.append(e)
-
-# elif event.get(e, 0) == None:
-# output.append(e)
-
- else:
-# last_identifier = ''
- last_identifier = event.get(e, 1)
-# last_values = []
- last_values = event.get_pfield_list(e)
- output.append(e)
-
- return ''.join(output)
+#import csd.sco.event as event
+from csd.sco.preprocessor import value_to_carry
def main():
# Get input
stdin = sys.stdin.readlines()
score = ''.join(stdin)
-
- print replace(score),
+
+ print value_to_carry(score),
if __name__ == '__main__':
main()
View
1  demo/pfunc.py
@@ -179,6 +179,7 @@ def pfunc(score, statement, identifier, pfield, formula):
def main():
# Get argv from command-line
+# print sys.argv
statement = list(sys.argv[1])
identifier = eval(sys.argv[2])
pfield = eval(sys.argv[3])
Please sign in to comment.
Something went wrong with that request. Please try again.