コード例 #1
0
def show_terminal_output(current_state):
    ng_fifths = pt_utils.c_chrom_to_f_circle(current_state.current_binary)
    ng_kp = pt_keypattern.get_binary_KP(current_state.current_kpdve[0],
                                        current_state.current_kpdve[1])
    print("Ob" + bin(ng_fifths)[2:].zfill(12) + "    " +
          current_state.current_root_string() + " as " +
          current_state.current_function_string())
    print("Ob" + bin(ng_kp)[2:].zfill(12) + " of " +
          current_state.current_conv_tonic_string() + " " +
          current_state.current_conv_pattern_string())
コード例 #2
0
ファイル: pt_live_graph.py プロジェクト: timsum/harmony_pipe
    def __init__(self, ref_state):
        self.current_state = ref_state

        self.window = tkinter.Tk()
        self.window.wm_title("Representations of Harmonic Process")

        self.fig, self.ax = plt.subplots(4, figsize=(12,3))

        self.chr_img = self.ax[0].imshow(np.expand_dims(self.current_state.chroma_values, axis=0), vmin=0.0, vmax=1.0)
        self.ng_img = self.ax[1].imshow(self.heatmap_axis(pt_utils.c_chrom_to_f_circle(self.current_state.current_binary)))
        self.kp_img = self.ax[2].imshow(self.heatmap_axis(pt_keypattern.get_binary_KP(self.current_state.current_kpdve[0], self.current_state.current_kpdve[1])))

        plt.show(block=False)

        self.canvas = FigureCanvasTkAgg(self.fig, master=self.window)  # A tk.DrawingArea.
        self.canvas.draw()

        self.window.update()
コード例 #3
0
def multiple_kpdve_heatmap(kpdve_list, yticks=[], title=None):
    '''
    takes a kpdve list and turns it to a heatmap
    '''

    # get the binary values corresponding to the kpdve list
    states = [harmony_state.harmony_state(kpdve) for kpdve in kpdve_list]
    notegroup_list = np.array([
        pt_utils.c_chrom_to_f_circle(a_state.current_binary)
        for a_state in states
    ])
    np_notegroup_list = np.array([
        pt_utils.binary_notegroup_to_numpy_array(ng) for ng in notegroup_list
    ])
    np_notegroup_list_clr = numpy_matrix_by_circleindex(np_notegroup_list)

    # make a mask
    mask = 1 - np_notegroup_list

    # make a list of rgb tuples with sb.hls_palette()
    rgbtups = sb.hls_palette(12, h=hue, l=light, s=sat)
    #[sb.set_hls_values(0, h=a_kpdve[2], l=a_kpdve[1], s=a_kpdve[2]) for a_kpdve in kpdve_list]

    # use that as a colormap in the sb heatmap
    # seaborn.hls_palette(n_colors=12, h=0.01, s=0.9, l=0.65, as_cmap=False)¶

    fig, ax = plt.subplots(figsize=(6, len(np_notegroup_list) / 2.0))
    ticknames = pt_naming_conventions.circle_fifth_notes()

    sb.set(font_scale=1.4)
    sb.heatmap(np_notegroup_list_clr,
               ax=ax,
               mask=1 - np_notegroup_list,
               xticklabels=ticknames,
               yticklabels=yticks,
               linewidths=1,
               cmap=rgbtups,
               cbar=False,
               vmin=0,
               vmax=1)

    ax.set_title(title, fontsize=16)
    plt.show()
コード例 #4
0
def heatmap_col_mask_for_kpdve_bin(a_kpdve, ng):
    k = (pt_utils.single_bit_loc(
        pt_musicutils.circle_conv_lyd_center_for_KPDVE(a_kpdve))) % 12
    p = (pt_utils.single_bit_loc(
        pt_musicutils.circle_conv_tonic_for_KPDVE(a_kpdve))) % 12
    d = (pt_utils.single_bit_loc(
        pt_musicutils.circle_root_note_for_KPDVE(a_kpdve))) % 12
    e = (pt_utils.single_bit_loc(
        pt_musicutils.circle_ext_note_for_KPDVE(a_kpdve))) % 12

    kpd_part = [k, p, d]
    msk_lin = [1]

    ng_circ = pt_utils.c_chrom_to_f_circle(ng)
    bin_notes = pt_utils.binary_notegroup_to_numpy_array(ng_circ)

    notes = list(bin_notes * np.array([i for i in range(12)]))
    mask = np.array([0, 0, 0] + (msk_lin * 2) + list(1 - bin_notes))

    full_column = np.array(kpd_part + (msk_lin * 2) + notes)
    return full_column, mask
コード例 #5
0
def analyze_binary_note_input(notegroup, v_opt=0):
    '''
    takes a chromatic pitch class set (derived from MIDI numbering (0-128) % 12), represented in binary like a piano keyboard:
    C D EF G A B
    100011000100 = F Major 7

    Parameters
    ----------
    notegroup : int
        a chromatic pitch class set (derived from MIDI numbering (0-128) % 12), represented in binary like a piano keyboard:
      C D EF G A B
    v_opt : int (index)
        selects from voicing options in keypattern.py.
        default: all voicings (often increases stability, though costs in speed.  Live audio should probably stick to thirds)
        
    Returns
    -------
    np.array(listlength x 5)
        returns kpdve list as np.array

    >>> analyze_binary_note_input(0)
    array([[12,  7,  7,  7,  7]])

    >>> analyze_binary_note_input(0b100011000100)
    array([[ 0,  0,  0,  4,  3],
           [ 0,  3,  0,  4,  3],
           [ 0,  6,  0,  4,  3],
           [ 1,  6,  6,  4,  3],
           [10,  1,  2,  4,  3],
           [11,  0,  1,  4,  3],
           [11,  1,  1,  4,  3],
           [11,  4,  1,  4,  3]])

    '''

    if notegroup == 0:
        return np.array([pt_utils.MODVALS])
    # convert the input to circle of fifths mode and analyze
    return pt_keypattern.get_KPDVE_list_for_notegroup(pt_utils.c_chrom_to_f_circle(notegroup), v_opt=v_opt)
コード例 #6
0
ファイル: harmony_state.py プロジェクト: timsum/harmony_pipe
    def change_notegroup(self, notegroup, v_opt=0):
        '''
        Generate the harmonic context from a binary notegroup

        Parameters
        ----------
        notegroup : int
            a chromatic pitch-class set.

        Returns
        -------
        True if changed, False if no change is NECESSARY

        '''

        # BIG QUESTION: SHOULD THIS STAY IN THE SAME CHORD IF THE or OPERATIONS ALLOWS?
        if (notegroup == self.current_binary):
            return False

        # if ((notegroup & self.current_binary) == notegroup): # NO CHANGE IN CHORD IS *NECESSARY*
        #     self.current_binary = notegroup
        #     return False

        probe_kpdve = partita.analyze_binary_input_for_closest_KPDVE(
            notegroup, self.current_kpdve)
        self.valid_state = (np.array_equal(probe_kpdve,
                                           pt_utils.MODVALS) == False)

        if self.valid_state:
            self.current_kpdve = np.copy(probe_kpdve)
            self.current_binary = notegroup
            ng_fifths = pt_utils.c_chrom_to_f_circle(self.current_binary)
            ng_kp = pt_keypattern.get_binary_KP(self.current_kpdve[0],
                                                self.current_kpdve[1])
            if (ng_fifths & ng_kp != ng_fifths):
                print("mismatch in fifths/kp")
            return True

        return False
コード例 #7
0
ファイル: pt_live_graph.py プロジェクト: timsum/harmony_pipe
 def update_window_for_state(self):
     self.chr_img.set_data(np.expand_dims(pt_utils.numpy_chrom_to_circle(self.current_state.chroma_values), axis=0))
     self.ng_img.set_data(self.heatmap_axis(pt_utils.c_chrom_to_f_circle(self.current_state.current_binary)))
     self.kp_img.set_data(self.heatmap_axis(pt_keypattern.get_binary_KP(self.current_state.current_kpdve[0], self.current_state.current_kpdve[1])))
     self.fig.canvas.flush_events()