Пример #1
0
def simple_mod(start, measure, transpose):
    selected = sco.select(measure, {0: 'i'})

    # Change start times
    selected = selection.operate_numeric(selected, 2, lambda x: x + start)

    # Transpose
    _transpose = lambda x: x * pow(2, transpose / 12.0)
    selected = selection.operate_numeric(selected, 5, _transpose)

    return sco.merge(measure, selected)
Пример #2
0
def simple_mod(start, measure, transpose):
    selected = sco.select(measure, {0: 'i'})
    
    # Change start times
    selected = selection.operate_numeric(selected, 2, lambda x: x + start)
    
    # Transpose
    _transpose = lambda x: x * pow(2, transpose / 12.0)
    selected = selection.operate_numeric(selected, 5, _transpose)
    
    return sco.merge(measure, selected)
Пример #3
0
def map_(score, pattern, pfield_index_list, pfunction, *args):
    '''Performs a pfunction on multiple pfields in a score, returning
    a new score.
    
    Example:
        
        >>> def add(x, y):
        ...     return x + y
        ... 
        >>> sco.map_("""
        ... i 1 0 4 1.0 440
        ... i 1 4 4 0.5 880""", {0: 'i'}, 5, add, 777)
        '\\ni 1 0 4 1.0 1217\\ni 1 4 4 0.5 1657'
    
    Example using lambda function::
        
        >>> sco.map_("""
        ... i 1 0 4 1.0 440
        ... i 1 4 4 0.5 880""", {0: 'i'}, 5, lambda x: x * 3)
        '\\ni 1 0 4 1.0 1320\\ni 1 4 4 0.5 2640'

    See :term:`pattern`, :term:`pfield_index_list`, :term:`pfunction`,
    :term:`score`

    '''

    selection_ = select(score, pattern)
    selection_ = selection.operate_numeric(selection_, pfield_index_list,
                                           pfunction, *args)
    return merge(score, selection_)
Пример #4
0
def map_(score, pattern, pfield_index_list, pfunction, *args):
    '''Performs a pfunction on multiple pfields in a score, returning
    a new score.
    
    Example:
        
        >>> def add(x, y):
        ...     return x + y
        ... 
        >>> sco.map_("""
        ... i 1 0 4 1.0 440
        ... i 1 4 4 0.5 880""", {0: 'i'}, 5, add, 777)
        '\\ni 1 0 4 1.0 1217\\ni 1 4 4 0.5 1657'
    
    Example using lambda function::
        
        >>> sco.map_("""
        ... i 1 0 4 1.0 440
        ... i 1 4 4 0.5 880""", {0: 'i'}, 5, lambda x: x * 3)
        '\\ni 1 0 4 1.0 1320\\ni 1 4 4 0.5 2640'

    See :term:`pattern`, :term:`pfield_index_list`, :term:`pfunction`,
    :term:`score`

    '''
    
    selection_ = select(score, pattern)
    selection_ = selection.operate_numeric(selection_, pfield_index_list,
                                           pfunction, *args)
    return merge(score, selection_)
Пример #5
0
def complex_play(start, measure):
    selected = sco.select(measure, {0: 'i'})

    # Add 1
    selected = selection.operate_numeric(selected, 5, lambda x: x + 1)

    # Delay, transpose, swap pan, half amp
    s2 = selected.copy()
    s2 = selection.operate_numeric(s2, 2, lambda x: x + start + 0.125)
    _transpose = lambda x: x * pow(2, 7 / 12.0)
    s2 = selection.operate_numeric(s2, 5, _transpose)
    s2 = selection.operate_numeric(s2, 6, lambda x: 1.0 - x)
    s2 = selection.operate_numeric(s2, 4, lambda x: x * 0.5)

    output = []
    output.append(sco.merge(measure, selected))
    output.append(sco.merge(measure, s2))
    return ''.join(output)
Пример #6
0
def complex_play(start, measure):
    selected = sco.select(measure, {0: 'i'})

    # Add 1
    selected = selection.operate_numeric(selected, 5, lambda x: x + 1)
    
    # Delay, transpose, swap pan, half amp
    s2 = selected.copy()
    s2 = selection.operate_numeric(s2, 2, lambda x: x + start + 0.125)
    _transpose = lambda x: x * pow(2, 7 / 12.0)
    s2 = selection.operate_numeric(s2, 5, _transpose)
    s2 = selection.operate_numeric(s2, 6, lambda x: 1.0 - x)
    s2 = selection.operate_numeric(s2, 4, lambda x: x * 0.5)
    
    output = []
    output.append(sco.merge(measure, selected))
    output.append(sco.merge(measure, s2))
    return ''.join(output)    
Пример #7
0
def test(n, expect, score_dict, pfield, pf_function, *args):
    result = selection.operate_numeric(score_dict, pfield, pf_function, *args)
    did_pass = result == expect

    return did_pass, n, 'operate_numeric()', str(expect), str(result)
Пример #8
0
    output.append(sco.merge(measure, s2))
    return ''.join(output)


#for i in range(0, 8):
#    print simple_mod(i * 4, my_measure, i * 2),

#print complex_play(0, my_measure)
#print complex_play(4, my_measure)

# Serializing functions
f_list = (lambda x: x + 1, lambda x: x * 2)
this_measure = my_measure
selected = sco.select(this_measure, {0: 'i'})
for f in f_list:
    selected = selection.operate_numeric(selected, 5, f)
this_measure = sco.merge(this_measure, selected)
print 'this measure', this_measure

# Functions need arguments, specify pfield(s)
# Multiple types of functional pfunc type things:
#    do_all(pfield_index_list, pfunc, *args)       # processes all ievents
#                                                  # in block
#    do(pattern, pfield_index_list, [pfunc, *args], ...)  # with pattern
'''
def punch(score, *func_args):
 
this_measure = my_measure

punch(this_measure, [do_all(5, lambda x: (x + y), 1)],
                    [do({1: 2}, 6, lambda x: 1.0 - x)])
Пример #9
0
    return ''.join(output)    
    
    
#for i in range(0, 8):
#    print simple_mod(i * 4, my_measure, i * 2),
    
#print complex_play(0, my_measure)
#print complex_play(4, my_measure)


# Serializing functions
f_list = (lambda x: x + 1, lambda x: x * 2)
this_measure = my_measure
selected = sco.select(this_measure, {0: 'i'})
for f in f_list:
    selected = selection.operate_numeric(selected, 5, f)
this_measure = sco.merge(this_measure, selected)
print 'this measure', this_measure


# Functions need arguments, specify pfield(s)
# Multiple types of functional pfunc type things:
#    do_all(pfield_index_list, pfunc, *args)       # processes all ievents
#                                                  # in block
#    do(pattern, pfield_index_list, [pfunc, *args], ...)  # with pattern
'''
def punch(score, *func_args):
 
this_measure = my_measure

punch(this_measure, [do_all(5, lambda x: (x + y), 1)],