Skip to content

Commit

Permalink
feat: 新增Part4 列出Chord結果列表
Browse files Browse the repository at this point in the history
- 但缺乏時間尺度
  • Loading branch information
Keycatowo committed Feb 19, 2023
1 parent ba7c657 commit 50c4031
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
9 changes: 7 additions & 2 deletions pages/4-Chord_recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from src.st_helper import convert_df, show_readme
from src.chord_recognition import (
plot_chord_recognition,
plot_binary_template_chord_recognition
plot_binary_template_chord_recognition,
chord_table
)

st.title("Chord Recognition")
Expand Down Expand Up @@ -65,8 +66,12 @@
# plot_chord_recognition
with tab1:
st.subheader("plot_chord_recognition")
fig4_1, ax4_1 = plot_chord_recognition(y_sub, sr)
fig4_1, ax4_1, chord_max = plot_chord_recognition(y_sub, sr)
st.pyplot(fig4_1)
chord_results = chord_table(chord_max)
chord_results_df = pd.DataFrame(chord_results)
st.write(chord_results_df)


# plot_binary_template_chord_recognition
with tab2:
Expand Down
16 changes: 14 additions & 2 deletions src/chord_recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def plot_chord_recognition(y, sr) :
ax[1, 0].set_yticklabels(chord_labels)
ax[1, 0].grid()
plt.tight_layout()
return fig, ax
return fig, ax, chord_max

def plot_binary_template_chord_recognition(y, sr) :

Expand All @@ -213,4 +213,16 @@ def plot_binary_template_chord_recognition(y, sr) :
libfmp.b.plot_chromagram(X_chord, ax=[ax[1, 0], ax[1, 1]], Fs=Fs_X, clim=[0, 1], xlabel='',
title='Binary templates of the chord recognition result')
plt.tight_layout()
return fig, ax
return fig, ax


def chord_table(chord_max):

chord_labels = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B'] + ['Cm', 'C#m', 'Dm', 'D#m', 'Em', 'Fm', 'F#m', 'Gm', 'G#m', 'Am', 'A#m', 'Bm']

# 計算chord_max依照第一個軸的最大值的index
chord_max_index = np.argmax(chord_max, axis=0)
# 用index找出對應的chord_labels
chord_results = [chord_labels[i] for i in chord_max_index]

return chord_results

0 comments on commit 50c4031

Please sign in to comment.