def midi_live(midifilename, quarternote_s=0.5, skip_leading_rests=True): """ Given a MIDI file, play it live on the printer """ p = P.Printer() p.initialize() # Use a class as a local namespace to capture variables class Position: z = 0 # This is our current Z position in microsteps direction = -1 # This is the direction of travel (negative = down) # Local function that handles note direction and timing def play_note(freq, time_s): # Turn around if we're about to hit the top or bottom steps = freq * time_s if not (-80000 <= Position.z + Position.direction * steps <= 0): Position.direction *= -1 # Send a blocking motor move p.move_z(Position.direction * freq * time_s, freq, 150) # Update the dead-reckoning Z position Position.z += Position.direction * steps mf = music21.midi.MidiFile() mf.open(midifilename) mf.read() soundstream = music21.midi.translate.midiFileToStream(mf) for track in soundstream.elements: for i in track.flat.elements: # Play a note on the printer (and clear the skip rests flag) if isinstance(i, music21.note.Note): play_note(i.pitch.frequency, i.duration.quarterLength * quarternote_s) skip_leading_rests = False # Pause the correct amount of time for a rest elif isinstance(i, music21.note.Rest): if not skip_leading_rests: time.sleep(i.duration.quarterLength * quarternote_s)
from OpenFL import Printer, FLP #use this for a real printer (comment this line if you plan to use a Dummy Printer): p = Printer.Printer() # OR # uncomment this for Dummy printer (comment out line 4 and line 47, or this will fail): #p=Printer.DummyPrinter() # variables (don't change these) F = FLP packets = F.Packets() grid = p.read_grid_table() if len(p.list_blocks()) >= 0: p.delete_block(0) packets.append( F.LayerStart(0) ) # This puts a marker at the beginning of the block to tell the printer the layer is beginning # Main function def flpMaker(x, y): # first turn off the laser and move to a point packets.append(F.LaserPowerLevel(0)) packets.append(F.XYMove([[x, y, 2000]])) # Turn on the laser packets.append(F.LaserPowerLevel(32768)) # adjust the number in the command below if a longer or shorter laser duration is desired. Must be an unsigned 16 bit integer.
def midi_live(midifilename, quarternote_s=0.5, frequency_factor=1.0, skip_leading_rests=True): """ Given a MIDI file, play it live on the printer """ p = P.Printer() if p.state() != P.State.MACHINE_READY_TO_PRINT: p.initialize() else: # We still want to ensure we start in a known state, with z at the limit: import OpenFL.FLP as FLP # Move z up by more than the z height at 15 mm/s. p.move_z(FLP.ZMove.usteps_up_per_mm * 200.0, feedrate=FLP.ZMove.usteps_up_per_mm * 15.0) # Use a class as a local namespace to capture variables p.move_z(FLP.ZMove.usteps_up_per_mm * -10.0, feedrate=FLP.ZMove.usteps_up_per_mm * 15.0) class Position: zbounds_mm = (-10, -150) zbounds_ustep = (zbounds_mm[0] * FLP.ZMove.usteps_up_per_mm, zbounds_mm[1] * FLP.ZMove.usteps_up_per_mm) # This is our current Z position in microsteps: z_ustep = FLP.ZMove.usteps_up_per_mm * -10.0 direction = -1 # This is the direction of travel (negative = down) # Local function that handles note direction and timing def play_note(freq, time_s): # Turn around if we're about to hit the top or bottom steps = freq * time_s next_z_would_be = Position.z_ustep + Position.direction * freq * time_s if Position.direction < 0: if next_z_would_be < min(Position.zbounds_ustep): Position.direction = 1 else: if next_z_would_be > max(Position.zbounds_ustep): Position.direction = -1 # Send a blocking motor move p.move_z(Position.direction * freq * time_s, freq, 80) # Update the dead-reckoning Z position Position.z_ustep += Position.direction * steps print 'Reading MIDI file...' mf = music21.midi.MidiFile() mf.open(midifilename) mf.read() soundstream = music21.midi.translate.midiFileToStream(mf) print 'read {} streams'.format(len(soundstream.elements)) for track in soundstream.elements: for i in track.flat.elements: # Play a note on the printer (and clear the skip rests flag) if isinstance(i, music21.note.Note): play_note(i.pitch.frequency * frequency_factor, i.duration.quarterLength * quarternote_s) skip_leading_rests = False # Pause the correct amount of time for a rest elif isinstance(i, music21.note.Rest): if not skip_leading_rests: time.sleep(i.duration.quarterLength * quarternote_s)
#!/usr/bin/env python """ This is a Python script that prints an FLP """ import OpenFL.Printer as P if __name__ == '__main__': parser = argparse.ArgumentParser(description="Print a .flp") parser.add_argument('input', metavar='input', type=str, help='source flp file') args = parser.parse_args() p = P.Printer() p.initialize() p.write_block(0, args.input) p.start_printing(0)
# -*- coding: utf-8 -*- from Tkinter import * from OpenFL import Printer, FLP import time p = Printer.Printer() #change to Printer.Printer before using p._command(Printer.Command.CMD_INITIALIZE, wait=False, expect_success=True) root = Tk() root.title('Z Jogger') offsetList = [187310.0] print("Current Z Position = " + str(-1 * (sum(offsetList)) / 1000.0)) #This section sets the read and write parameters for USB communication, according to the settings above def writeUSB(data): return dev.write(RX_EP, data, timeout=None) def readUSB(buffsize=1024): return dev.read(TX_EP, buffsize, timeout=10000) def upMove(): global jog jog = incrementZ.get() offsetList.append(float(jog) * 2.5) print("Current Z Position = " + str(-1 * (sum(offsetList)) / 1000.0)) p.move_z(jog, 4000)
# -*- coding: utf-8 -*- from Tkinter import * import tkMessageBox as mb from OpenFL import Printer, FLP import numpy as np #p=Printer.Printer() # Uncomment for real printer p = Printer.DummyPrinter( ) #This is for testing, comment when using real printer p.initialize() root = Tk() # name of the Tkinter window: root.title('Photonsters Form 1+ Grid Calibration Tool') # use the Photonsters image as a window icon #img = Image("photo", file="Photonsters.gif") #root.tk.call('wm','iconphoto',root._w,img) # use ravel to flatten the grid table to 1D gridCal = np.ravel(p.read_grid_table()) #set radio buttons to be integers gridPos = IntVar() tickNumber = IntVar() tickNumber.set("100") """ This section is a list of variables used for dynamically updating the label text of the grid points """ textVar01 = StringVar() textVar02 = StringVar()