Python Forum
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Jython for music
#1
Background My apologies if this isn't even python! I have been trying to look up what the differences and similarities are and people tell me that it's "close enough" to Python. I decided the Homework section probably suited me the best because of the limited extent of my knowledge, but this is not a homework assignment of any kind, you won't be doing my work for me by helping, answers need not be cryptic!  Tongue  

The project
I have been writing a program based on (I can't put links in yet, sorry)  jythonmusic.me but find the instructions very incomplete for my purposes. I have hacked my way about it with no programming background because I needed a program to drive an iPad app using eye tracking software on a Windows PC. An extract from the code I have so far is attached. Yes, I'm aware it's full of redundant lines and that it's not very elegant! I intend to tidy things up as my knowledge grows. The code runs in JEM3 from the Jython website download area or it says Terminal Window, Komodo or jEdit will do. The version copied in may not do very much; because I am not able to use lists yet, the program is repetitive and runs to thousands of lines which all do the same basic thing. If running this version, the functional area is the very top red bar.

The help I need
At line 26 I ask for the user to make an input which becomes rootPitch. I would really like a way to be able to vary the rootPitch in the program, e.g. via a button, menu, etc. Problem being that the code cannot execute at all without having a starting definition for rootPitch, and when I ask for it in this way it doesn't seem to be possible to override it with new input, as this value is permenantly saved. Is there a way to re-write things so it will allow rootPitch to be re-defined without restarting the script? I want it to be fully accessible with only mouse movements (not even clicks) once loaded and the starting root input.

What I understand
Very little. If the answer is something like "just parse it as a variable string" then please can you point me to an article or something I can Google to find out what you mean me to actually do, because I have literally no programming background, I am only doing this because I thought I could do it, not because I have relevant expertise of any kind.

Thanks!

#[python]#######################################################
#Switchable octave piano or Figurenotes piano overlay for Eye Gaze users. 
#Option to define root pitch to assist in use with Thumbjam, as other variables are controlled in Thumbjam

from music import *
from gui import *
from midi import *

mOutput = MidiOut()                             #used to select MIDI output option

Play.setInstrument(CLARINET)                    # set desired MIDI instrument (0-127)

d = Display("Eye Gaze for Thumbjam", 977, 690)               # load image and create display with appropriate size
pianoIcon = Icon("Fn_cols_side_Gradient_Outline_7.png", 977, 690)      # image for display
d.add(pianoIcon)                                # place image at top-left corner


###############

###Define areas for mouseover use
noteDohLoudIcon = Icon("Rect_01c.png") #image for note only, transparent appearance - temporarily using violet option so I can see them, will need to change back to invisible when complete
d.add(noteDohLoudIcon, 273, 42)                         #adds note icon in default position


##########################################################
rootPitch = input("Enter root note")               #Calls for user input for pitch of lowest note - always use C.



############################################################################
# define callback functions

def beginNote2a( self, event ):
   

       
         Play.noteOn( rootPitch, 90 )    # play root pitch plus a tone
         mOutput.noteOn( rootPitch, 90)  #Start MIDI event Root as input  
         #d.add( downKeyIcons[i], iconWidths[i], 0 )     #This function now adds ALL the icons and they stay there 
        


###################################################################################

def endNote2a( self, event ):
 

 
    
        Play.noteOff( rootPitch )        # stop note applies to mouseover
        mOutput.noteOff( rootPitch)     #Stops midi 

########################################

# associate callback functions with GUI events

noteDohLoudIcon.onMouseEnter ( beginNote2a)
noteDohLoudIcon.onMouseExit ( endNote2a)

###############################################
###################################
[/python]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Jython macro which uses PythonInterpreter and Redis script gives an error rkanumola 2 2,227 Oct-30-2019, 07:37 AM
Last Post: rkanumola
  Jython code throws ImportError when invoked from a Java jar dchucks 6 7,082 Aug-02-2018, 05:09 AM
Last Post: dchucks

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020