def chord(sheetId, chordId): if request.method == 'GET': chord = db.session.query(Chord).join(Sheet).filter( Sheet.id == sheetId).filter(Chord.id == chordId).first() return jsonify(chord.to_dict()) elif request.method == 'PUT': data = request.json chord = db.session.query(Chord).join(Sheet).filter( Sheet.id == sheetId).filter(Chord.id == chordId).first() shorthand_notation = data['name'] chord.name = shorthand_notation chord.notes = ' '.join(ch.from_shorthand(shorthand_notation)) inversions = [ ' '.join(ch.first_inversion(chord.notes.split(' '))), ' '.join(ch.second_inversion(chord.notes.split(' '))), ' '.join(ch.third_inversion(chord.notes.split(' '))) ] chord.inversions = [ Inversion(name=str(i), notes=notes) for i, notes in enumerate(inversions) ] chord.updated_at = dt.utcnow() db.session.commit() return jsonify(chord.to_dict()), 201 elif request.method == 'DELETE': db.session.query(Chord).filter(Chord.sheet_id == sheetId).filter( Chord.id == chordId).delete() db.session.query(Inversion).filter( Inversion.chord_id == chordId).delete() db.session.commit() return jsonify( {"msg": f"Chord {chordId} has been deleted from Sheet {sheetId}."}), 201
def sheets(): if request.method == 'GET': sheets = Sheet.query.all() return jsonify({'sheets': [s.to_dict() for s in sheets]}) elif request.method == 'POST': data = request.json sheet = Sheet(name=data['name']) chords = [] for c in data['chords']: shorthand_notation = c['name'] chord = Chord(name=shorthand_notation) chord.notes = ' '.join(ch.from_shorthand(shorthand_notation)) print(chord.notes) inversions = [ ' '.join(ch.first_inversion(chord.notes.split(' '))), ' '.join(ch.second_inversion(chord.notes.split(' '))), ' '.join(ch.third_inversion(chord.notes.split(' '))) ] chord.inversions = [ Inversion(name=str(i), notes=notes) for i, notes in enumerate(inversions) ] chords.append(chord) sheet.chords = chords db.session.add(sheet) db.session.commit() return jsonify(sheet.to_dict()), 201
def invert(chord): k = len(chord) - 1 r = random.randint(0, k) if r==1: return chords.first_inversion(chord) elif r==2: return chords.second_inversion(chord) elif r==3: return chords.third_inversion(chord) else: return chord
def sheet(sheetId): if request.method == 'GET': sheet = Sheet.query.get(sheetId) return jsonify({'sheet': sheet.to_dict()}) elif request.method == 'PUT': data = request.json shorthand_notation = data['name'] chord = Chord(name=shorthand_notation, sheet_id=sheetId) chord.name = shorthand_notation chord.notes = ' '.join(ch.from_shorthand(shorthand_notation)) inversions = [ ' '.join(ch.first_inversion(chord.notes.split(' '))), ' '.join(ch.second_inversion(chord.notes.split(' '))), ' '.join(ch.third_inversion(chord.notes.split(' '))) ] chord.inversions = [ Inversion(name=str(i), notes=notes) for i, notes in enumerate(inversions) ] chord.updated_at = dt.utcnow() db.session.add(chord) db.session.commit() return jsonify(chord.to_dict()), 201 elif request.method == 'DELETE': chordIds = [ chord.id for chord in db.session.query(Chord).join(Sheet).filter( Sheet.id == sheetId).all() ] db.session.query(Sheet).filter(Sheet.id == sheetId).delete() for id in chordIds: db.session.query(Chord).filter(Chord.sheet_id == sheetId).filter( Chord.id == id).delete() db.session.query(Inversion).filter( Inversion.chord_id == id).delete() db.session.commit() return jsonify({"msg": f"Sheet {sheetId} has been deleted."}), 201
print(flatList) builtChords = progressions.to_chords(flatList, key) ## Create bars for each chord comp = [] lead = [] for chord in builtChords: modChord = chord #randomly invert before adding if random() > 0.7: # and randVal < 0.8: modChord = chords.second_inversion(modChord) elif random() > 0.7: modChord = chords.third_inversion(modChord) container = NoteContainer(modChord) #write a melody leadBar = Bar(key, meter) noteLengths = [2, 4, 8] lastNote = Note() lastNoteLength = 4 while leadBar.is_full() == False: if random() < 0.8: currentBeat = leadBar.current_beat # add a note # if random() < 0.5 and len(leadBar) > 0: # n = Note(intervals.second(lastNote.name, key))