Skip to content

Instantly share code, notes, and snippets.

@bearpelican
Created February 28, 2019 23:26
Show Gist options
  • Save bearpelican/eef65737bb8e074884878cfc6c1bbaa3 to your computer and use it in GitHub Desktop.
Save bearpelican/eef65737bb8e074884878cfc6c1bbaa3 to your computer and use it in GitHub Desktop.
Chord change after adding: `scale = [s+sec_offset for s in scale]`
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%reload_ext autoreload\n",
"%autoreload 2\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path\n",
"from roman_to_symbol import *\n",
"from tab_parser import *"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"file_path = Path('hooktheory/xml/w/wyd-krakow-2016/blogoslawieni-milosierni/verse.xml')\n",
"content = load_data(file_path)\n",
"root = xml_parser(content)\n",
"metadata, version = get_metadata(root)\n",
"segments, num_measures = get_lead_sheet(root, version)\n",
"mode = int(metadata['mode']) if metadata['mode'] is not None else 1\n",
"beats_in_measure = int(metadata['beats_in_measure'])\n",
"melody, chord = segments_parser(segments, mode, beats_in_measure)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"6"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mode"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"OrderedDict([('sd', '5'),\n",
" ('fb', None),\n",
" ('sec', '4'),\n",
" ('sus', 'sus4'),\n",
" ('pedal', None),\n",
" ('alternate', None),\n",
" ('borrowed', None),\n",
" ('isRest', False),\n",
" ('event_on', 72.0),\n",
" ('event_off', 76.0),\n",
" ('event_duration', 4.0)])"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"chord[-2]"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"v_iv_sus4 = OrderedDict([('sd', '5'),\n",
" ('fb', None),\n",
" ('sec', '4'),\n",
" ('sus', 'sus4'),\n",
" ('pedal', None),\n",
" ('alternate', None),\n",
" ('borrowed', None),\n",
" ('isRest', False),\n",
" ('event_on', 72.0),\n",
" ('event_off', 76.0),\n",
" ('event_duration', 4.0)])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Without scale shift:"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"OrderedDict([('root', 0),\n",
" ('bass', 12),\n",
" ('comp_vec',\n",
" array([12, None, None, 12, 19, None, None, None, None], dtype=object)),\n",
" ('composition', array([12, 12, 19], dtype=object)),\n",
" ('quality', ''),\n",
" ('chord_type', 5),\n",
" ('chord_mode', 0),\n",
" ('isRest', False),\n",
" ('event_on', 72.0),\n",
" ('event_off', 76.0),\n",
" ('event_duration', 4.0),\n",
" ('inv', 0),\n",
" ('sus', 'sus4'),\n",
" ('alter', None),\n",
" ('emb', []),\n",
" ('alter_map', None),\n",
" ('symbol', 'C sus4')])"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"chord_parser(v_iv_sus4, mode='6', key_offset=0)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"With fix:"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"OrderedDict([('root', 0),\n",
" ('bass', 12),\n",
" ('comp_vec',\n",
" array([12, None, None, 17, 19, None, None, None, None], dtype=object)),\n",
" ('composition', array([12, 17, 19], dtype=object)),\n",
" ('quality', ''),\n",
" ('chord_type', 5),\n",
" ('chord_mode', 0),\n",
" ('isRest', False),\n",
" ('event_on', 72.0),\n",
" ('event_off', 76.0),\n",
" ('event_duration', 4.0),\n",
" ('inv', 0),\n",
" ('sus', 'sus4'),\n",
" ('alter', None),\n",
" ('emb', []),\n",
" ('alter_map', None),\n",
" ('symbol', 'C sus4')])"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"chord_parser(v_iv_sus4, mode='6', key_offset=0)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment