Category Archives: Music

Python Spotify Genre Cube v2

Spotify version

Next to do: Lasercut a wooden cube with better lettering.

Run the python part on a server

and

First export some API credentials

export SPOTIPY_CLIENT_ID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export SPOTIPY_CLIENT_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export SPOTIPY_REDIRECT_URI="http://localhost:8080/callback"

Code below:

from flask import Flask, request, redirect
from requests_oauthlib import OAuth2Session
from requests.auth import HTTPBasicAuth
import requests
import json
import spotipy
from spotipy.oauth2 import SpotifyOAuth
from pprint import pprint
from time import sleep
import spotipy.util as util
import sys
import paho.mqtt.client as mqttClient
import time
import os
import subprocess

Connected = False


broker_address = "MQTTSERVER"
port = 1883


def on_connect(client, userdata, flags, rc):
    if rc == 0:
        print("Connected to broker")
        global Connected
        Connected =True
    else:
        print("Connection failed")

def on_message(client, userdata, message):
    print (message.payload)
    myurl = 'spotify:playlist:' + str(message.payload.decode())

    results = sp.start_playback(context_uri=myurl, offset={"position": 1})

client = mqttClient.Client("PythonSpotifyGenreCube")
client.on_connect = on_connect
client.on_message = on_message

client.connect(broker_address, port=port,keepalive=60 )
client.loop_start()
time.sleep(4) # Wait for connection setup to complete
client.subscribe('spotify/playlist')
#client.loop_stop()    #Stop loop

#while Connected != True:
#    client.loop()
#    time.sleep(0.1)
#    print("test")
#    client.subscribe('spotify/playlist')



app = Flask(__name__)

AUTH_URL = 'https://accounts.spotify.com/authorize'
TOKEN_URL = 'https://accounts.spotify.com/api/token'
REDIRECT_URI = 'http://localhost:8080/callback'
CLIENT_ID = "xxxxxxxxxxxxxxxxxx"
CLIENT_SECRET = "xxxxxxxxxxxxxxxxxxxxx"
SCOPE = [
    "user-read-email",
    "playlist-read-collaborative"
]

@app.route("/login")
def login():
    spotify = OAuth2Session(CLIENT_ID, scope=SCOPE, redirect_uri=REDIRECT_URI)
    authorization_url, state = spotify.authorization_url(AUTH_URL)
    return redirect(authorization_url)

@app.route("/callback", methods=['GET'])
def callback():
    code = request.args.get('code')
    res = requests.post(TOKEN_URL,
        auth=HTTPBasicAuth(CLIENT_ID, CLIENT_SECRET),
        data={
            'grant_type': 'authorization_code',
            'code': code,
            'redirect_uri': REDIRECT_URI
        })
    return json.dumps(res.json())


username = "fashice"
scope = "user-read-playback-state,user-modify-playback-state,playlist-read-private"
util.prompt_for_user_token(username,scope,client_id='xxxxxxxxxxxxxxxxxxxxx',client_secret='xxxxxxxxxxxxxxxxxxxxxxxxxxxx',redirect_uri='http://localhost:8080/callback')

sp = spotipy.Spotify(client_credentials_manager=SpotifyOAuth(scope=scope))

# Shows playing devices
res = sp.devices()
pprint(res)


# Change track
#sp.start_playback(uris=['spotify:track:6gdLoMygxxxxxxxxxxxxxxx'])
#results = sp.start_playback(context_uri=myurl, offset={"position": 1})


## Change volume
#sp.volume(100)
#sleep(2)
#sp.volume(50)
#sleep(2)
#sp.volume(100)
#


playlists = sp.user_playlists(username)

#for playlist in playlists['items']:
#    print(playlist['name'])


playlists = sp.current_user_playlists()
#print (playlists)
for playlist in playlists['items']:
    print(playlist['id'] + ' ' +  playlist['name'])



#if __name__ == '__main__':
#   app.run(port=8080,debug=True)


while Connected != True:
    time.sleep(0.1)
    client.subscribe('spotify/playlist')

try:
    while True:
        time.sleep(1)


except KeyboardInterrupt:
    print ("exiting")
    client.disconnect()
    client.loop_stop()

Spotify control using python

For usage in this project:

Goto https://developers.spotify.com and add a APP

Write down the Client_id Client_secret and Redirect URL (callback)

Create a bash and python script

#!/bin/bash
export SPOTIPY_CLIENT_ID=2f660e11e70743febdxxxxxxxxxxxxx
export SPOTIPY_CLIENT_SECRET=b0741452a4fe43xxxxxxxxxxxxx
export SPOTIPY_REDIRECT_URI="http://localhost:8080/callback"

python3 spot.py $1

spot.py

import spotipy
from spotipy.oauth2 import SpotifyOAuth
from pprint import pprint
from time import sleep
import spotipy.util as util
import sys

username = "username"
scope = "user-read-playback-state,user-modify-playback-state,playlist-read-private"
util.prompt_for_user_token(username,scope,client_id=SPOTIPY_CLIENT_ID,client_secret=SPOTIPY_CLIENT_SECRET,redirect_uri=SPOTIPY_REDIRECT_URI)

sp = spotipy.Spotify(client_credentials_manager=SpotifyOAuth(scope=scope))

# Shows playing devices
res = sp.devices()
pprint(res)

myurl = 'spotify:playlist:' + sys.argv[1]

# Change track
results = sp.start_playback(context_uri=myurl, offset={"position": 1})

## Change volume example
#sp.volume(100)
#sleep(2)
#sp.volume(50)
#sleep(2)

playlists = sp.user_playlists(username)

playlists = sp.current_user_playlists()
for playlist in playlists['items']:
    print(playlist['id'] + ' ' +  playlist['name'])

Run bash script as follows.

playlistplayspotify.sh 0bJvpsn0TDxxxxxxxxxxxx
(0bJvpsn0TDxxxxxxxxxxxx – is playlist ID, as example below)

OUTPUT:

python3 spot.py 0bJvpsn0TDxxxxxxxxxxxx
{'devices': [{'id': 'e86eada2a91e29a396acxxxxxxxxxxxxxxxxxxxx',
              'is_active': True,
              'is_private_session': False,
              'is_restricted': False,
              'name': 'laptop',
              'type': 'Computer',
              'volume_percent': 100},
             {'id': '8571468b6c41973ccb0axxxxxxxxxxxxxxxxxxxx',
              'is_active': False,
              'is_private_session': False,
              'is_restricted': False,
              'name': 'DESKTOP-xxxxxxx',
              'type': 'Computer',
              'volume_percent': 76},
             {'id': '6c592503aa5a22b2fbdxxxxxxxxxxxxxxxxxxxxxx',
              'is_active': False,
              'is_private_session': False,
              'is_restricted': False,
              'name': 'TX-NR1030',
              'type': 'AVR',
              'volume_percent': 41}]}
0bJvpsn0TDxxxxxxxxxxxx Best Classical Music Of All Time
5aL9jeGMCAxxxxxxxxxxxx Programming music
37i9dQZEVCxxxxxxxxxxxx Discover Weekly
6pEJuA1UYJxxxxxxxxxxxx Highland/Small/Border Pipe Music
5p8Tabf5Zwxxxxxxxxxxxx Folk Instrumentals ( Celtic, Irish, Nordic, ... )
1oy8Ek4ddBxxxxxxxxxxxx Lounge
37i9dQZF1Dxxxxxxxxxxxx Irish Folk
etc etc

Shaders using Bonzomatic

Saw some demo-scene shader showdowns on YT the other day.

Two guys live programming shaders in less than a hour!

Fun to play with .. bonzomatic.
This shader program is realtime being compiled and the effect is shown on the background.

Below version I made using an example is changing to the music being played. (Fast Fourier transform function, see my other post about this)

RFID music playlist genre selector.

Just a proof of concept for a friend.

This one works with Logitech Media Server and Spotify playlists, but also works with generic LMS playlists when you change the url)

Selecting music using the RFID reader module in my game.
(i didn´t have a spare reader)

Cardboard box with rfid tags inside.

Looks nicer using laser lettering.

Maybe a tetrahedron for play,next,previous and stop?
And another with volume settings?

Simple node-red switcher

URL being called:

http://logictechmediaserver:9000/plugins/spotty/index.html?action=play&index=8.12

Harp with leds

A ledstrip on a Harp, now I can see the strings at night!

Woohoo .. ( Little harp in the background (autoharp))

Well .. its a pity that the distance of the leds is NOT the same as the strings distance.

I could light up the string to be played, or even cooler …
When using FFT code (Fast Fourier Transform), I could light up the string being played!
I’m probably going to try to implement this at a later time.

Planxty Irwin Concertina Notation

While working on a harmony for Irmgard and me in Musescore, i tought it would be nice to have it also in another notation.

Above a Musescore screenshot.

When using below button assignment, we can easily rewrite above into another notation.

Write musescore as MusicML/mxl Music xml.

Install xml2abc from https://wim.vree.org/svgParse/xml2abc.html

python xml2abc.py INPUTFILE.mxl output.abc

My abc file

X:1
T:Planxty Irwin
C:OCarolan
L:1/4
M:3/4
I:
K:G
V:1 treble nm="Henri" snm="H"
V:1
|: d | B2 d | c2 A | F2 A | G3/2 d/ B | A G F | G3/2 A/ B | D2 E | F2 d | B2 d | c2 A | F2 A |
 G3/2 d/ B | A G F | G3/2 A/ B | e d c | B2 d | B3/2 c/ B | B G B | c3/2 d/ c | c A F | G d e |
 c d e | d3/2 c/ A | d c A | B c d | c B A | F G A | G3/2 d/ B | A G F | G3/2 A/ B | e d c | B2 :|

Using below bash script you can convert this to PDF WITH concertina notations.
WARNING: I didn't include all keys (yet).
NOTE: Easy to adjust to other notations.
#!/bin/bash
if [ $# -lt 2 ]; then
    print "script orgname convertname"
    exit 1
fi
: > parced
org=$1
abc=$2
cat $1 | awk '/^\|/ {exit} {print}' > header
cat $1 | grep "|" | tr -d '[0-9]:/'> parse
(
cat parse | while read ; do 
echo $REPLY
echo -n "w: "

for word in $(echo $REPLY) ; do

	if [ "$word" == "|" ] ; then echo -n " | " 
	elif [ "$word" == "D" ] ; then echo -n " 2 ";
	elif [ "$word" == "G" ] ; then echo -n " 3 ";
	elif [ "$word" == "B" ] ; then echo -n " 4 ";
	elif [ "$word" == "d" ] ; then echo -n " 5 ";
	elif [ "$word" == "g" ] ; then echo -n " 6 ";
	elif [ "$word" == "b" ] ; then echo -n " 7 ";
	else echo -n " * "
	fi
done
echo ""

echo -n "w: "

for word in $(echo $REPLY) ; do

	if [ "$word" == "|" ] ; then echo -n " | " 
	elif [ "$word" == "F" ] ; then echo -n " 2 ";
	elif [ "$word" == "A" ] ; then echo -n " 3 ";
	elif [ "$word" == "c" ] ; then echo -n " 4 ";
	elif [ "$word" == "e" ] ; then echo -n " 5 ";
	elif [ "$word" == "f" ] ; then echo -n " 6 ";
	elif [ "$word" == "a" ] ; then echo -n " 7 ";
	elif [ "$word" == "E" ] ; then echo -n " 4' ";  # <============ example 2nd row
	else echo -n " * "
	fi
done
echo ""

done
) >> parced
cat header parced > $abc
abcm2ps -x -O - "$abc" | ps2pdf  -sPAPERSIZE=a4 - "$(echo  $abc | cut -f2 -d/ | sed 's/abc/pdf/g')"

Example output (Harmony part)

Made a case for my page turner

Using OpenScad I ended up with this .. a nice minimal design

Openscad file (Jup thats all)

difference(){
    difference(){

    union(){
cube([96,30,12],center = true);
        translate([41,0,5])
cube([15,30,23],center = true);
translate([-41,0,5])
cube([15,30,23],center = true);
    }
cube([90,30-6,24],center = true);
}
union(){
    difference(){
translate([0,0,5])
cube([90,20,30],center = true);
translate([0,0,5])
cube([77,20,35],center = true);
    }
}
}

Late Burns Night and St Patrick’s Day

We had a delayed Burns night, seems a bit of a habit of our band.
But with Covid, who knows, maybe we are celebrating Burns Night 2020.

I wanted to make Haggis “bitterballen” (Fried balls) but Irmgard has no frying pan. So I made some Haggis sausage rolls.

The others made also a lot of Scottish/Irish themed food. (Too much again) But i don’t have the recipes.

We played some old tunes, and some new. Talking eating and drinking, time flies!

Irmgard and I played a duet on the Harp and some new tunes on the Concertina.

Wellll the recipes:

I wanted to make this one:
https://cookingwithbry.com/haggis-bon-bons-recipe/

Instead I made this:

  • 392g haggis, canned haggis ( Holiday 2022, stuffed a load of cans in our car )
  • 3 Sausages (that is about 200 gr)
  • Bunch fresh parsley, finely chopped
  • 320g ready rolled all-butter puff pastry
  • 2 tbsp Dijon mustard
  • 1 free-range egg, beaten

Mix haggis, sausagemeat and parsley.

I used square “bladerdeeg” for pastry, made a roll out of one square filled with the haggis. (Takes about of 13 sheets).
Brushed on the beaten egg, and put on baking paper.
20 Minutes in a 180 degrees oven.
Cut up each roll in 3-4 parts.

Flute and more

I’ve been playing tin whistles/low whistle for a long time, but I love flutes.

My first try on a Concert metal flute was in a bus with the “Eendracht” to germany. There is a photo but i’ve trashed stuff a long time ago.
A old girlfriend (Noelle) let me try it. Apparently I didn’t do it that badly.

Now 30 odd years later, I picked it up again. But now on the Irish Wooden flute.

We bought it 10+ years, and occasionally I pick it up and try to play some slow airs.

I love the sound of flutes. But I’m bad at lip embouchure.
The Irish Flute makes it even harder, there is no Lip plate.

We have some books, and Coline attended to the Flute lessons in Ireland.

Tunes i’ve been practicing on flute at this time:

  • Angels Meadow
  • Passing Places
  • Breizh
  • A tune i am writing/composing at this time

(Some are Uilleann/ Low Whistle tunes I already know)
Having a large collection of tunes does not make it easy.
But having trouble myself to get all the octaves correct, I limit myself to certain tunes.

I’ll post some progress / examples at a later date.

Very interesting book and DVD!

Yes, we even tried beatboxing with the flute. (see below)

Some nice flute playing below:

And the best players (according to my opinion)

Sir James Galway
Matt Malloy
Michael McGoldrick
Jethro Tull
Séamus Tansey
Calum Stewart – I play one of his tunes on Uilleann
Paddy Carty
Robert Harvey
Flook stuff

Egyptian flutes are amazing : Lookup Erik the Flutemaker for more exceptional flutes.

Pan flutes from Peru and some asian bamboo flutes are amazing also

I’ve made a overtone flute a while ago, these ones doesn´t have holes.
I’ll post something about those soon.

The last example with overtone reminds me to post my findings about.
(Mongolian) throatsinging, overtone flutes and Altai playing.
(look it up .. amazing, We’ve been to a Hanggai concert)
But i’m drifting away from flutes and the topic in general.

Above McGoldrick with some Fred Morrison tunes i also play.

Greg Pattillo from Project Trio

Overtone flute example