示例#1
0
    def __init__(self, octave=60):
        self.octave = octave
        self.time = time.time()
        #self.pitch_map = PitchMap([x+octave for x in 2,9,12,17,23,28,31], variance=50)
        chords = ((-10, -3, 0, 5, 11, 16, 19), (-17, -10, -3, 12, 17, 23, 26),
                  (-15, -7, 0, 11, 16, 21, 24), (-7, 0, 4, 9, 14, 19, 23))

        self.pitch_maps = []
        for chord in chords:
            self.pitch_maps.append(
                PitchMap([x + octave for x in chord], variance=50))

        self.pitch_map = self.pitch_maps[0]
        self.rhythm = random.choice(((1, 1, 2), (1, 1, 2, 1, 1, 1, 1, 2)))
        self.velocity_map = DataMap(
            [random.randint(60, 127) for _ in range(7)], variance=50)
        self.jaggedness = 0.

        Autonomous.__init__(self)
        events.listen('facing_front', self.front_shift)
        events.listen('facing_back', self.back_shift)
示例#2
0
 def __init__(self, octave=60):
     self.octave = octave
     self.time = time.time()        
     #self.pitch_map = PitchMap([x+octave for x in 2,9,12,17,23,28,31], variance=50)
     chords = (
           (-10,-3,0,5,11,16,19),
           (-17,-10,-3,12,17,23,26),
           (-15,-7,0,11,16,21,24),
           (-7,0,4,9,14,19,23)
           )
     
     self.pitch_maps = []
     for chord in chords:
         self.pitch_maps.append(PitchMap([x+octave for x in chord], variance=50))
     
     self.pitch_map = self.pitch_maps[0]
     self.rhythm = random.choice( ((1,1,2), (1,1,2,1,1,1,1,2)) )
     self.velocity_map = DataMap([random.randint(60, 127) for _ in range(7)], variance=50)
     self.jaggedness = 0.
     
     Autonomous.__init__(self)
     events.listen('facing_front', self.front_shift)
     events.listen('facing_back', self.back_shift)
示例#3
0
class Polycrystalline(Autonomous):
    pitch_map = None
    r = 0
    octave = 48
    time = 0
    increments = (-3,-1,2,4,-2)
    facing = True
    i = 0
    skip = 0
    dur = 0.3
    jazziness = None
    pitch_maps = None
    
    def __init__(self, octave=60):
        self.octave = octave
        self.time = time.time()        
        #self.pitch_map = PitchMap([x+octave for x in 2,9,12,17,23,28,31], variance=50)
        chords = (
              (-10,-3,0,5,11,16,19),
              (-17,-10,-3,12,17,23,26),
              (-15,-7,0,11,16,21,24),
              (-7,0,4,9,14,19,23)
              )
        
        self.pitch_maps = []
        for chord in chords:
            self.pitch_maps.append(PitchMap([x+octave for x in chord], variance=50))
        
        self.pitch_map = self.pitch_maps[0]
        self.rhythm = random.choice( ((1,1,2), (1,1,2,1,1,1,1,2)) )
        self.velocity_map = DataMap([random.randint(60, 127) for _ in range(7)], variance=50)
        self.jaggedness = 0.
        
        Autonomous.__init__(self)
        events.listen('facing_front', self.front_shift)
        events.listen('facing_back', self.back_shift)
    
    def front_shift(self):
        pass#self.pitch_map.setItems(self.front_chord)

    def back_shift(self):
        pass#self.pitch_map.setItems(self.back_chord)
            
    def _play(self):
        self.jazziness = Jazziness.retrieve()
        i = 0
        skip = False
        self.time = time.time()
        while self.playing:
            swing = self.jazziness.swing
            jaggedness = self.jazziness.jaggedness
            if jaggedness > .5:
                midi.setSustain(False)
            else:
                midi.setSustain(True)
            
            for beattype in 'long', 'short':
                pitch = self.pitch_map.pick()
                dur = self.dur
                if self.rhythm[self.i] == 1:
                    i+=1
                elif self.rhythm[self.i] == 2 and not skip:
                    skip = True
                elif skip:
                    skip = False
                    i += 1
                    if beattype == 'long':
                        dur *= swing
                    else:
                        dur *= (1-swing)
                    self.time += dur
                    time.sleep(self.time - time.time())
                    continue
                
                velocity = int(scale(self.velocity_map.pick(), 
                                     0, 127, 
                                     (1.-jaggedness)*.4*127, 127-(1.-jaggedness)*.6*127))
                self._out(pitch, 0.2, velocity, 1)
                self.skip = 0
                self.i = (self.i + 1) % len(self.rhythm)
                
                if beattype == 'long':
                    dur *= swing
                else:
                    dur *= (1-swing)
                self.time += dur
                time.sleep(self.time - time.time())
示例#4
0
class Polycrystalline(Autonomous):
    pitch_map = None
    r = 0
    octave = 48
    time = 0
    increments = (-3, -1, 2, 4, -2)
    facing = True
    i = 0
    skip = 0
    dur = 0.3
    jazziness = None
    pitch_maps = None

    def __init__(self, octave=60):
        self.octave = octave
        self.time = time.time()
        #self.pitch_map = PitchMap([x+octave for x in 2,9,12,17,23,28,31], variance=50)
        chords = ((-10, -3, 0, 5, 11, 16, 19), (-17, -10, -3, 12, 17, 23, 26),
                  (-15, -7, 0, 11, 16, 21, 24), (-7, 0, 4, 9, 14, 19, 23))

        self.pitch_maps = []
        for chord in chords:
            self.pitch_maps.append(
                PitchMap([x + octave for x in chord], variance=50))

        self.pitch_map = self.pitch_maps[0]
        self.rhythm = random.choice(((1, 1, 2), (1, 1, 2, 1, 1, 1, 1, 2)))
        self.velocity_map = DataMap(
            [random.randint(60, 127) for _ in range(7)], variance=50)
        self.jaggedness = 0.

        Autonomous.__init__(self)
        events.listen('facing_front', self.front_shift)
        events.listen('facing_back', self.back_shift)

    def front_shift(self):
        pass  #self.pitch_map.setItems(self.front_chord)

    def back_shift(self):
        pass  #self.pitch_map.setItems(self.back_chord)

    def _play(self):
        self.jazziness = Jazziness.retrieve()
        i = 0
        skip = False
        self.time = time.time()
        while self.playing:
            swing = self.jazziness.swing
            jaggedness = self.jazziness.jaggedness
            if jaggedness > .5:
                midi.setSustain(False)
            else:
                midi.setSustain(True)

            for beattype in 'long', 'short':
                pitch = self.pitch_map.pick()
                dur = self.dur
                if self.rhythm[self.i] == 1:
                    i += 1
                elif self.rhythm[self.i] == 2 and not skip:
                    skip = True
                elif skip:
                    skip = False
                    i += 1
                    if beattype == 'long':
                        dur *= swing
                    else:
                        dur *= (1 - swing)
                    self.time += dur
                    time.sleep(self.time - time.time())
                    continue

                velocity = int(
                    scale(self.velocity_map.pick(), 0, 127,
                          (1. - jaggedness) * .4 * 127,
                          127 - (1. - jaggedness) * .6 * 127))
                self._out(pitch, 0.2, velocity, 1)
                self.skip = 0
                self.i = (self.i + 1) % len(self.rhythm)

                if beattype == 'long':
                    dur *= swing
                else:
                    dur *= (1 - swing)
                self.time += dur
                time.sleep(self.time - time.time())