Skip to content

Instantly share code, notes, and snippets.

@alanholding
Created September 5, 2021 12:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanholding/ad712c3bbd754944dd57ca8f83e848be to your computer and use it in GitHub Desktop.
Save alanholding/ad712c3bbd754944dd57ca8f83e848be to your computer and use it in GitHub Desktop.
Outputs a CSV file with the counts of plugins in VCV Rack patch files.
'''
2021-09-05
Outputs a CSV file with the counts of plugins in VCV Rack patch files.
'''
import os
import json
import csv
def get_list_of_vcv_rack_patches(patches_directory):
patches_list = []
# Thanks to https://stackoverflow.com/a/41447012
# r=root, d=directories, f = files
for r, d, f in os.walk(patches_directory):
for file in f:
if file.endswith(".vcv"):
# print(os.path.join(r, file))
patches_list.append(os.path.join(r, file))
return patches_list
def open_patch_and_return_data(filename):
with open(filename, "r") as read_file:
return json.load(read_file)
# Set the directory of your VCV Rack Patches here
patches_directory = "/Users/alan/Documents/Rack/patches/"
# Read the file names and adds them to the list_of_vcv_rack_patches list.
list_of_vcv_rack_patches = get_list_of_vcv_rack_patches(patches_directory)
# Make a dictionary to hold the names and counts of the modules in the patches
plugins_dictionary = {}
# Goes through the files and extracts the data
for filename in list_of_vcv_rack_patches:
# Get VCV Rack patch file JSON data
json_data = open_patch_and_return_data(filename)
# Debugging
# print(json.dumps(json_data, indent=4))
# Modules data
if json_data["modules"]:
plugins_data = json_data["modules"]
else:
print(f"Required data is missing in VCV Rack patch file {filename}")
continue
# Go through the list of modules
for plugin in plugins_data:
# Skip version number for now as I can't be bothered doing the error checking
# plugin_squashed_name = f'{plugin["plugin"]} {plugin["model"]} {plugin["version"]}'
plugin_squashed_name = f'{plugin["plugin"]} {plugin["model"]}'
# Check for plugin in the dictionary and add it if not present
if not plugin_squashed_name in plugins_dictionary:
plugins_dictionary[plugin_squashed_name] = 0
# Increment the plugin count by one
plugins_dictionary[plugin_squashed_name] = plugins_dictionary[plugin_squashed_name] + 1
# Sort by count
# Thanks to https://stackoverflow.com/a/2258273
sorted_plugins = sorted(plugins_dictionary.items(), key=lambda x: x[1], reverse=True)
# Write out a CSV file with the results
# Thanks to https://pythonspot.com/files-spreadsheets-csv/
with open('vcv_rack_modules_by_count.csv', 'w', newline='') as csvfile:
filewriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
filewriter.writerow(['Plugin', 'Count'])
for k, v in sorted_plugins:
filewriter.writerow([k, v])
# There's probably a better way to do this but I'm sick of this script now :)
patches_count = len(list_of_vcv_rack_patches)
patches_plural = "file" if patches_count == 1 else "files"
print(f"Scanned {patches_count} VCV Rack patch {patches_plural}.")
print(f"Your top five modules (ignoring version numbers) are…")
for m in range(5):
print(f"\t{m+1}. {sorted_plugins[m][0]} ({sorted_plugins[m][1]})")
print("Open the CSV file 'vcv_rack_modules_by_count.csv' for more information.")
# EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment