Building Chord Progressions using Stacks, Part 2
Photo by Nahir Giorgio on Unsplash
Continuing with my previous post on chord progressions, I am going to play a few more chord progression examples. Remember, I am using the music21 Python library to understand and play the music and I am using this musical stack structure:
from music21 import *
class MusicStack:
def __init__(self):
self.items = stream.Stream()
def push(self, item):
self.items.append(item)
def pop(self):
if self.is_empty():
raise IndexError("Sorry, your stack is empty")
else:
return self.items.pop()
def peek(self):
if self.is_empty():
raise IndexError("Sorry, your stack is empty")
else:
return self.items[-1]
def is_empty(self):
return self.items == []
Thanks for reading Learning Data Structures and Algorithms with Music! Subscribe for free to receive new posts and support my work.
Read more

