def init_piano(self): keymap_filename = 'pianoeletronico.kmp' notes_manager = NotesManager() notes_manager.load_file(util.app_file_path(os.path.join('keymaps', keymap_filename))) self.midi = midi.Midi() self.midi_output = midi.Output(self.midi.get_default_output_id(), 0) self.piano = Piano(notes_manager, self.midi_output) self.piano.set_instrument(0, 0)
def __init__(self, ui=None, track=None, width=None, height=None, x=0, y=0): self.ui = ui # Offset on left side, leaving space for timestamps self.offset = len("00:00.000 ") if self.ui != None: logger.log("Using ui") self.height, self.width = list(map(int, self.ui.size())) self.width -= self.offset else: logger.log("Not using ui") self.height, self.width = 10, 10 self.cursorY = self.height / 2 self.cursorX = 44 self.track = track self.bpm = self.track.beatsPerMinute self.tpb = self.track.ticksPerBeat self.seconds = 60.0 / self.tpb / self.bpm #Begin and end using real time #self.length = self.track.getLengthInSec() #self.begin = 0.0 #self.end = (self.height-1) * 60.0 / self.bpm #self.step = 60.0 / self.bpm #Begin and end using beats self.length = self.track.getLengthInBeats() self.begin = 0 self.end = self.height - 1 self.step = 1 logger.log("Track's length: %.2f beats" % self.length) self.beats = [] for i in range(int(self.track.getLengthInBeats() + 1)): self.beats.append([]) logger.log("width = %d" % self.width) ## Create display window if self.width > KEYS: displayWidth = KEYS + self.offset else: displayWidth = self.width + self.offset MIN = (KEYS - self.width) / 2 MAX = (KEYS - self.width) / 2 + self.width if self.ui != None: self.display = self.ui.newWindow(self.height, displayWidth, "display", x, y) self.ui.setWindow(self.display) ## Connect to Piano self.piano = Piano() self.player = Player() self.player.start() self.player.setPiano(self.piano) self.piano.autoconnect() self.playing = False ## Create metronome beatLength = 60.0 / self.bpm self.metronome = Metronome(self.down, beatLength)
def __init__(self): self.screen_size = (1366, 768) # (width, height) self.camera_size = (640, 480) # (width, height) self.key_quit = 'q' self.aruco_dict = cv2.aruco.getPredefinedDictionary( cv2.aruco.DICT_ARUCO_ORIGINAL) self.update_piano_corners_freq = 5 # Number of frames to update piano corners self.img_to_project = np.zeros( (self.camera_size[1], self.camera_size[0], 3), np.uint8) # self.display = Display(screen_width=self.screen_size[0]) self.piano = Piano() self.cam_to_proj = None # Transformation from camera to projector coordinates self.song = [ "C#4", "C4", "F#5", "B4", "G5", "E5", "E5", "br", "F5", "D5", "D5", "br", "C5", "D5", "E5", "F5", "G5", "G5", "G5", "br", "G5", "E5", "E5", "br", "F5", "D5", "D5", "br", "C5", "E5", "G5", "G5", "C5" ]
from piano import Piano from recorder import Recorder from logger import Logger from sys import argv import mido ### Call python test_recorder.py ## ## Options: ## -i Select input device ## -o Select output device ### Create instance of Piano and Recorder p = Piano() rec = Recorder() log = Logger(p, rec) ### Options verbose = "-v" in argv ### Select input and output devices if "-i" in argv: [ins, outs] = p.listDevices() print("[+] List of input devices") for i in range(len(ins)): print("%d: %s" % (i + 1, ins[i])) inDev = ins[int(input("Select input device: ")) - 1] else: inDev = mido.get_input_names()[0] if "-o" in argv: print("[+] List of output devices")
import cv2 import time import numpy as np from piano import Piano from threading import Thread piano = Piano() protoFile = "hand/pose_deploy.prototxt" weightsFile = "hand/pose_iter_102000.caffemodel" nPoints = 22 threshold = 0.2 input_source = "input.mp4" def playMusic(x, y): Thread(target=piano.press, args=( x, y, )).start() if __name__ == "__main__": cap = cv2.VideoCapture(input_source, cv2.CAP_FFMPEG) hasFrame, frame = cap.read() frameWidth = frame.shape[1] frameHeight = frame.shape[0]
def init_piano(self): self.create_midi_driver() self.piano = Piano(self.config.get_keymap_file_path('pianoeletronico.kmp'), self.midi_output) self.active_channels.append(0) self.piano.set_instrument(0, 0)
""" Generates wav file using PySynth: https://mdoege.github.io/PySynth/#s """ import os import pysynth from piano import Piano output_folder = "wav" key_list = Piano().key_list if not os.path.exists(output_folder): os.makedirs(output_folder) for key in key_list: print("Generating %s" % key['note']) note_str = key['note'].lower() pysynth.make_wav([[note_str, 4]], fn=os.path.join(output_folder, "%s.wav" % key['note']))