예제 #1
0
파일: tk_dialogs.py 프로젝트: kcsaff/CA
def _file_save_dialog(last_filename = ''):
    filename = tkFileDialog.asksaveasfilename(parent=_use_tkinter(),
                                              initialdir=os.path.dirname(last_filename),
                                              filetypes=[('CA scanner native',
                                                          '*.ca.zip')])
    if filename:
        events.put(Event('file_save', filename=filename))
예제 #2
0
파일: comm.py 프로젝트: kcsaff/CA
 def handle(self):
     data = self.request.recv(1024)
     if data:
         #print 'S: ', data
         events.put(eval('Event(%s)' % data))
         self.request.send('1')
     else:
         self.request.send('0')
예제 #3
0
    def run(self):
        shift = False
        ctrl = False
        alt = False
        clock = pygame.time.Clock()
        while self._run.is_set():
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    events.put(events.QuitEvent())
                    continue

                if event.type == pygame.ACTIVEEVENT:
                    events.put(events.RefreshEvent())
                    continue

                if event.type == pygame.VIDEORESIZE:
                    events.put(events.ResizeEvent(event.w, event.h))
                    continue

                if event.type not in [pygame.KEYDOWN, pygame.KEYUP]:
                    continue
                if event.key in [pygame.K_RSHIFT, pygame.K_LSHIFT]:
                    shift = (event.type == pygame.KEYDOWN)
                elif event.key in [pygame.K_RCTRL, pygame.K_LCTRL]:
                    ctrl = (event.type == pygame.KEYDOWN)
                elif event.key in [pygame.K_RALT, pygame.K_LALT]:
                    alt = (event.type == pygame.KEYDOWN)
                elif event.type == pygame.KEYDOWN:
                    if shift:
                        if event.key == pygame.K_DOWN:
                            event.key = keys.KEY_SF
                        elif event.key == pygame.K_UP:
                            event.key = keys.KEY_SR
                        elif event.key == pygame.K_LEFT:
                            event.key = keys.KEY_SLEFT
                        elif event.key == pygame.K_RIGHT:
                            event.key = keys.KEY_SRIGHT
                        elif event.key == pygame.K_TAB:
                            event.key = keys.KEY_STAB

                    events.put(
                        events.KeyboardDownEvent(event.key, event.unicode))
                elif event.type == pygame.KEYUP:
                    events.put(
                        events.KeyboardUpEvent(event.key,
                                               chr(event.key & 0xff)))
            clock.tick(120)
예제 #4
0
    def fire_event(self,data):
        ''' got a event from the remote entity, fire it along...


        Event data structure:::
        {
            "name":"$$$$"
            "..."

        }

        '''
        if data['name'] not in events.base.events:
            logger.critical('event "%s" tried to fire but not found in event tree!'%data['name'])
            return
        data['id']=self.ID

        event=events.base.events[data['name']](data)
        event.entity=self
        events.put(event)
예제 #5
0
파일: tk_dialogs.py 프로젝트: kcsaff/CA
def _file_open_dialog(last_filename = ''):
    filename = tkFileDialog.askopenfilename(parent=_use_tkinter(),
                                            initialdir=os.path.dirname(last_filename))
    if filename:
        events.put(Event('file_open', filename=filename))
예제 #6
0
    def run(self):
        delete_keys = self.delete_keys
        drum_keys = [k.lower() for k in delete_keys]
        drum_key_to_note = []
        for octave in xrange(6):
            drum_key_to_note += [n+(12*octave)
                                 for n in [48, 50, 52, 53, 55, 57, 59]]

        key_to_midi = ['a', 'w', 's', 'e', 'd', 'f', 't', 'g', 'y', 'h',
                       'u', 'j', 'k']
        key_to_midi_octave = 0
        key_to_midi_state = {}
        midi_state = set()

        row_keys = {keys.KEY_UP: -1, keys.KEY_DOWN: 1}
        move_track_keys = {keys.KEY_SR: -1, keys.KEY_SF: 1}
        shift_track_keys = {keys.KEY_SLEFT: 1, keys.KEY_SRIGHT: -1}
        offset_keys = {keys.KEY_LEFT: -1, keys.KEY_RIGHT: 1}
        octave_keys = {'-': -1, '+': 1}

        quantize_keys = ['1', '2', '3', '4', '0']

        pad = self.pad
        pad.erase()

        prev_time = None
        repaint = 0
        pad.find_font_size(self.pattern.len*3+20, len(self.pattern.tracks))
        while True:
            try:
                ev = events.get()
            except Exception:
                curr_time = int(self.player.get_time())
                if prev_time != curr_time:
                    prev_time = curr_time
                    self.paint(only_pos=True)

                continue

            if ev.event_type == events.EVENT_QUIT:
                events.put(ev)
                break

            if ev.event_type == events.EVENT_REFRESH:
                self.paint()
                continue

            if ev.event_type == events.EVENT_RESIZE:
                pad.resize(ev.width, ev.height)
                pad.find_font_size(self.pattern.len*3+20,
                                   len(self.pattern.tracks))
                self.paint()
                continue

            self._current_track = min(self._current_track,
                                      len(self.pattern.tracks) - 1)
            track = self.pattern.tracks[self._current_track]

            if ev.event_type == events.EVENT_MIDI_NOTE:
                # Process input values
                ntime = self.player.get_time()
                channel_note = (ev.channel, ev.note)
                if ev.midi_event_type == MIDI_EVENT_NOTE_ON:
                    if channel_note not in midi_state:
                        if self.rec:
                            track.note_on(ntime, ev.channel, ev.note,
                                          ev.velocity)
                        else:
                            track.seq_note_on(ev.channel, ev.note, ev.velocity)
                        midi_state.add(channel_note)
                elif ev.midi_event_type == MIDI_EVENT_NOTE_OFF:
                    if channel_note in midi_state:
                        if self.rec:
                            track.note_off(ntime, ev.channel, ev.note)
                        else:
                            track.seq_note_off(ev.channel, ev.note)

                        try:
                            midi_state.remove(channel_note)
                        except Exception:
                            pass

                    if not midi_state:
                        self.push_undo()
            elif ev.event_type == events.EVENT_MIDI_CONTROLLER:
                seq.set_control(track._midi_port, ev.value, ev.param,
                                ev.channel)
            elif ev.event_type == events.EVENT_MIDI_PITCHBEND:
                ntime = self.player.get_time()
                if self.rec:
                    track.pitchbend(ntime, ev.value, ev.channel)
                else:
                    track.seq_pitchbend(ev.value, ev.channel)

            elif ev.event_type == events.EVENT_KEY_DOWN:
                k = ev.key_code
                c = ev.char
                if c == ':':
                    command, parameters = sdlcurses.Menu(pad, commands=[
                        ('pl', ['_Pattern _Length']),
                        ('nd', ['_New', '_Drum Channel']),
                        ('nm', ['_New', '_Midi Channel']),
                        ('cp', ['_Clear _Pitchbend']),
                        ('e', ['_Edit Channel']),
                        ('en', ['_Edit Channel _Name']),
                        ('d', ['_Duplicate Channel']),
                        ('r', ['_Remove Channel']),
                        ('bpm', ['_Beats _per _minute']),
                    ]).run()

                    if command == 'nd':
                        name = parameters or 'Drum Channel'
                        track = project.DrumTrack(name, [' '] * track.len(),
                                                  "", 15, 44)
                        self.pattern.tracks.append(track)
                        self._current_track = len(self.pattern.tracks) - 1
                        TrackEditor(pad, track).run()
                    elif command == 'nm':
                        name = parameters or 'Midi Channel'
                        track = project.MidiTrack(name, track.len(), [],
                                                  [0] * track.len(), "", 0)
                        self.pattern.tracks.append(track)
                        self._current_track = len(self.pattern.tracks) - 1
                        TrackEditor(pad, track).run()
                    elif command == 'cp':
                        for i in xrange(track.len()):
                            track.clear(
                                i,
                                MIDI_EVENT_PITCH
                            )
                    elif command == 'd':
                        tmp_track = track.__class__()
                        tmp_track.load(track.dump())
                        self.pattern.tracks.append(tmp_track)
                        self._current_track = len(self.pattern.tracks) - 1
                    elif command == 'r':
                        self.pattern.tracks.remove(track)
                        self._current_track = min(self._current_track,
                                                  len(self.pattern.tracks) - 1)
                        pad.erase()
                    elif command == 'e':
                        TrackEditor(pad, track).run()
                    elif command == 'en':
                        track.name = parameters
                    elif command == 'bpm':
                        set_bpm(parameters, self.project)
                    elif command == 'pl':
                        self.pattern.resize(int(parameters))

                elif c in key_to_midi + drum_keys:
                    midi_note = None
                    if track.track_type == TRACK_TYPE_DRUM:
                        if c in drum_keys:
                            pos = drum_keys.index(c)
                            pos += self._track_offset * len(delete_keys)
                            midi_note = drum_key_to_note[pos]
                    else:
                        midi_note = (key_to_midi.index(c)
                                     + key_to_midi_octave * 12 + 60)

                    if not key_to_midi_state.get(midi_note):
                        events.put(events.MidiNoteEvent(MIDI_EVENT_NOTE_ON,
                                                        track.midi_channel,
                                                        midi_note, 127))
                        key_to_midi_state[midi_note] = True
                elif c == " ":
                    if self.player.playing():
                        self.player.stop()
                    else:
                        self.player.play(self.pattern)
                elif k in row_keys:
                    self._current_track = ((self._current_track + row_keys[k])
                                           % len(self.pattern.tracks))
                elif k in move_track_keys:
                    i = self._current_track
                    j = (i + move_track_keys[k]) % len(self.pattern.tracks)
                    self.pattern.tracks[i], self.pattern.tracks[j] = (
                        self.pattern.tracks[j], self.pattern.tracks[i]
                    )
                    self._current_track = (
                        (self._current_track + move_track_keys[k])
                        % len(self.pattern.tracks)
                    )
                elif k in shift_track_keys:
                    track.shift(shift_track_keys[k])
                elif k in offset_keys:
                    self._track_offset = (
                        (self._track_offset + offset_keys[k])
                        % (self.pattern.len / len(delete_keys))
                    )
                elif c in octave_keys:
                    key_to_midi_octave += octave_keys[c]
                elif c in delete_keys:
                    pos = (delete_keys.index(c) +
                           self._track_offset * len(delete_keys))
                    track.clear(pos)
                    self.push_undo()
                elif c in quantize_keys:
                    if True or track.track_type == TRACK_TYPE_DRUM:
                        pos = self._track_offset * len(delete_keys)
                        for i in range(len(delete_keys)):
                            track.quantize(pos + i, c)
                        self.push_undo()
                elif c == 'R':
                    self.rec = not self.rec
                elif k == keys.KEY_BACKSPACE:
                    self.pop_undo()
                elif k == keys.KEY_ENTER:
                    TrackEditor(pad, track).run()
                elif c == 'q' or k == keys.KEY_ESC:
                    break
            elif ev.event_type == events.EVENT_KEY_UP:
                k = ev.key_code
                c = chr(k & 0xff)
                if c in key_to_midi + drum_keys:
                    midi_note = None
                    if track.track_type == TRACK_TYPE_DRUM:
                        if c in drum_keys:
                            pos = drum_keys.index(c)
                            pos += self._track_offset * len(delete_keys)
                            midi_note = drum_key_to_note[pos]
                    else:
                        midi_note = (key_to_midi.index(c)
                                     + key_to_midi_octave * 12 + 60)

                    if key_to_midi_state.get(midi_note):
                        events.put(events.MidiNoteEvent(MIDI_EVENT_NOTE_OFF,
                                                        track.midi_channel,
                                                        midi_note, 127))
                        key_to_midi_state[midi_note] = False

            nowtime = time.time()
            if repaint < nowtime - 0.05:
                self._octave = key_to_midi_octave
                self.paint()
                repaint = nowtime