Skip to content

Commit 0b119b1

Browse files
committed
add a 'when play' icon
1 parent e16c049 commit 0b119b1

File tree

1 file changed

+69
-106
lines changed

1 file changed

+69
-106
lines changed

Diff for: AudioToAscii.py

+69-106
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# extra lib added
88
import NatronGui
9-
import os, time, tempfile, posixpath
9+
import sys, os, time, tempfile, posixpath
1010
from os import path
1111

1212
def getPluginID():
@@ -84,7 +84,7 @@ def kill_pid_player(tfKPP):
8484
def audioToAscii(audioFileATA, asciiFileATA, dimATA, fpsATA, durationATA, xHeightATA, yHeightATA):
8585
# Linux & OSX
8686
if NatronEngine.natron.isMacOSX():
87-
exec_file = "/audio2ascii.sh"
87+
exec_file = "/audio2ascii/audio2ascii.sh"
8888
# complet path (.replace space need by OSX!?)
8989
path_a2a = str(os.path.dirname(os.path.realpath(__file__)) + exec_file).replace(" ", "\ ") # strage need to remove 'replace' for path configfile on MacOSX
9090
# set input and output files
@@ -93,15 +93,15 @@ def audioToAscii(audioFileATA, asciiFileATA, dimATA, fpsATA, durationATA, xHeigh
9393
param_a2a = str(dimATA) + " " + str(fpsATA) + " " + str(durationATA) + " " + str(xHeightATA) + " " + str(yHeightATA)
9494
# Linux
9595
elif NatronEngine.natron.isLinux():
96-
exec_file = "/AudioCurve"
96+
exec_file = "/audio2ascii/AudioCurve"
9797
path_a2a = str(os.path.dirname(os.path.realpath(__file__)) + exec_file).replace(" ", "\ ")
9898
files_a2a = "-input \""+str(audioFileATA)+"\" -output \""+str(asciiFileATA)+"\""
9999
param_a2a = "-"+str(dimATA)+" -fps "+str(fpsATA)+" -frames "+str(durationATA)+" -cX "+str(xHeightATA)+" -cY "+str(yHeightATA)
100100
# Windows
101101
elif NatronEngine.natron.isWindows():
102-
exec_file = "/AudioCurve.exe"
102+
exec_file = "/audio2ascii/AudioCurve.exe"
103103
path_a2a = str(os.path.dirname(os.path.realpath(__file__)) + exec_file)
104-
files_a2a = "-input '"+str(audioFileATA)+"' -output '"+str(asciiFileATA)+"'"
104+
files_a2a = "-input \""+str(audioFileATA)+"\" -output \""+str(asciiFileATA)+"\""
105105
param_a2a = "-"+str(dimATA)+" -fps "+str(fpsATA)+" -frames "+str(durationATA)+" -cX "+str(xHeightATA)+" -cY "+str(yHeightATA)
106106
#audio2ascii.sh exist in local plugin path ?
107107
if os.path.exists(os.path.dirname(os.path.realpath(__file__)) + exec_file):
@@ -144,9 +144,8 @@ def animCurves(thisParam, fileAC, dimAC, fpsAC, durationAC ,frameStartAC):
144144
asciiAC.close()
145145

146146
def paramHasChanged(thisParam, thisNode, thisGroup, app, userEdited):
147-
148147
# Read config file
149-
config_file = str(os.path.dirname(os.path.realpath(__file__)) + "/AudioToAscii.config") #.replace(" ", "\ ") strange here remove for MacOSX needed line in AudioToAscii function
148+
config_file = str(os.path.dirname(os.path.realpath(__file__)) + "/audio2ascii/AudioToAscii.config") #.replace(" ", "\ ") strange here remove for MacOSX needed line in AudioToAscii function
150149
env_list = read_init_file(config_file)
151150

152151
# audio input file
@@ -246,22 +245,25 @@ def paramHasChanged(thisParam, thisNode, thisGroup, app, userEdited):
246245
app.pane1.Viewer1.pause()
247246
app.pane1.Viewer1.seek(thisNode.atFrameNum.get())
248247
app.pane1.Viewer1.startForward()
248+
thisNode.playSync.setIconFilePath(os.path.dirname(os.path.realpath(__file__)) + "/audio2ascii/play_enabled.png")
249249
else:
250250
error_man("Audio Editor", "You need to set a audio file before preview !")
251+
thisNode.refreshUserParamsGUI()
251252
# Stop preview
252253
if thisParam == thisNode.stopSync:
253254
if tmp_file:
254255
kill_pid_player(tmp_file)
255256
app.pane1.Viewer1.pause()
257+
thisNode.playSync.setIconFilePath(os.path.dirname(os.path.realpath(__file__)) + "/audio2ascii/play.png")
256258
else:
257259
error_man("Audio Editor", "You need to set a audio file before preview !")
258-
260+
thisNode.refreshUserParamsGUI()
259261
## / extra defs
260262

261263
def createInstance(app,group):
262264

263265
# Read variables in config file
264-
config_file = str(os.path.dirname(os.path.realpath(__file__)) + "/AudioToAscii.config") #.replace(" ", "\ ") strange here remove for MacOSX
266+
config_file = str(os.path.dirname(os.path.realpath(__file__)) + "/audio2ascii/AudioToAscii.config") #.replace(" ", "\ ") strange here remove for MacOSX
265267
env_list = read_init_file(config_file)
266268

267269
#Create all nodes in the group
@@ -325,10 +327,8 @@ def createInstance(app,group):
325327
lastNode.userNatron = lastNode.createPageParam("userNatron", "Settings")
326328
param = lastNode.createFileParam("inputFile", "Audio File")
327329
param.setSequenceEnabled(False)
328-
329330
#Add the param to the page
330331
lastNode.userNatron.addParam(param)
331-
332332
#Set param properties
333333
param.setHelp("Path to audio file.\nSignificant number of formats are supported including:\nMP3/4, WAV, W64, AIFF, OGG, FLAC.")
334334
param.setAddNewLine(True)
@@ -337,10 +337,8 @@ def createInstance(app,group):
337337
del param
338338

339339
param = lastNode.createButtonParam("editAudio", "Edit audio file")
340-
341340
#Add the param to the page
342341
lastNode.userNatron.addParam(param)
343-
344342
#Set param properties
345343
param.setHelp("Audio editor.\nYou can setup it in 'Editor Settings")
346344
param.setAddNewLine(False)
@@ -351,10 +349,8 @@ def createInstance(app,group):
351349

352350
# Group /
353351
param = lastNode.createGroupParam("setEditor", "Editor setting")
354-
355352
#Add the param to the page
356353
lastNode.userNatron.addParam(param)
357-
358354
#Set param properties
359355
param.setHelp("Unfold to setup audio editor ")
360356
param.setAddNewLine(True)
@@ -364,10 +360,8 @@ def createInstance(app,group):
364360

365361
param = lastNode.createFileParam("editApp", "Audio editor")
366362
param.setSequenceEnabled(False)
367-
368363
#Add the param to the group, no need to add it to the page
369364
lastNode.setEditor.addParam(param)
370-
371365
#Set param properties
372366
param.setHelp("Set the audio editor path")
373367
param.setAddNewLine(True)
@@ -384,10 +378,8 @@ def createInstance(app,group):
384378
param = lastNode.createStringParam("editParam", "Audio editor parameters")
385379
param.setType(NatronEngine.StringParam.TypeEnum.eStringTypeDefault)
386380
param.setDefaultValue("")
387-
388381
#Add the param to the group, no need to add it to the page
389382
lastNode.setEditor.addParam(param)
390-
391383
#Set param properties
392384
param.setHelp("Set the audio editor command line parameters")
393385
param.setAddNewLine(False)
@@ -404,10 +396,8 @@ def createInstance(app,group):
404396

405397
param = lastNode.createFileParam("curveFile", "Curve File")
406398
param.setSequenceEnabled(False)
407-
408399
#Add the param to the page
409400
lastNode.userNatron.addParam(param)
410-
411401
#Set param properties
412402
param.setHelp("")
413403
param.setAddNewLine(True)
@@ -422,10 +412,8 @@ def createInstance(app,group):
422412
("xy", "")]
423413
param.setOptions(entries)
424414
del entries
425-
426415
#Add the param to the page
427416
lastNode.userNatron.addParam(param)
428-
429417
#Set param properties
430418
param.setHelp("Curve dimensions X/Y(Left/Right)")
431419
param.setAddNewLine(True)
@@ -446,10 +434,8 @@ def createInstance(app,group):
446434
param.setDisplayMinimum(0, 0)
447435
param.setDisplayMaximum(100, 0)
448436
param.setDefaultValue(app.frameRate.get(), 0)
449-
450437
#Add the param to the page
451438
lastNode.userNatron.addParam(param)
452-
453439
#Set param properties
454440
param.setHelp("Calculate curve with this frame rate")
455441
param.setAddNewLine(True)
@@ -459,10 +445,8 @@ def createInstance(app,group):
459445

460446
param = lastNode.createBooleanParam("autoFR", "Auto")
461447
param.setDefaultValue(1)
462-
463448
#Add the param to the page
464449
lastNode.userNatron.addParam(param)
465-
466450
#Set param properties
467451
param.setHelp("If check, set frame rate to project frame rate")
468452
param.setAddNewLine(False)
@@ -476,10 +460,8 @@ def createInstance(app,group):
476460
param.setDisplayMinimum(0, 0)
477461
param.setDisplayMaximum(500, 0)
478462
param.setDefaultValue(240, 0)
479-
480463
#Add the param to the page
481464
lastNode.userNatron.addParam(param)
482-
483465
#Set param properties
484466
param.setHelp("Duration of the curve in frames")
485467
param.setAddNewLine(True)
@@ -491,10 +473,8 @@ def createInstance(app,group):
491473
param.setDisplayMinimum(0, 0)
492474
param.setDisplayMaximum(500, 0)
493475
param.setDefaultValue(100, 0)
494-
495476
#Add the param to the page
496477
lastNode.userNatron.addParam(param)
497-
498478
#Set param properties
499479
param.setHelp("Height of X deviation in pixels")
500480
param.setAddNewLine(True)
@@ -506,10 +486,8 @@ def createInstance(app,group):
506486
param.setDisplayMinimum(0, 0)
507487
param.setDisplayMaximum(500, 0)
508488
param.setDefaultValue(100, 0)
509-
510489
#Add the param to the page
511490
lastNode.userNatron.addParam(param)
512-
513491
#Set param properties
514492
param.setHelp("Height of Y deviation in pixels")
515493
param.setAddNewLine(True)
@@ -521,10 +499,8 @@ def createInstance(app,group):
521499
param.setDisplayMinimum(1, 0)
522500
param.setDisplayMaximum(500, 0)
523501
param.setDefaultValue(1, 0)
524-
525502
#Add the param to the page
526503
lastNode.userNatron.addParam(param)
527-
528504
#Set param properties
529505
param.setHelp("Start the generate curve at this frame on the timeline")
530506
param.setAddNewLine(True)
@@ -533,10 +509,8 @@ def createInstance(app,group):
533509
del param
534510

535511
param = lastNode.createButtonParam("currentFrame", "Current Frame")
536-
537512
#Add the param to the page
538513
lastNode.userNatron.addParam(param)
539-
540514
#Set param properties
541515
param.setHelp("Update start frame to current frame")
542516
param.setAddNewLine(False)
@@ -546,10 +520,8 @@ def createInstance(app,group):
546520
del param
547521

548522
param = lastNode.createButtonParam("importCurve", "Generate the curve")
549-
550523
#Add the param to the page
551524
lastNode.userNatron.addParam(param)
552-
553525
#Set param properties
554526
param.setHelp("Generate curve from parameters")
555527
param.setAddNewLine(True)
@@ -567,10 +539,8 @@ def createInstance(app,group):
567539
param.setMaximum(2.14748e+09, 1)
568540
param.setDisplayMinimum(0, 1)
569541
param.setDisplayMaximum(500, 1)
570-
571542
#Add the param to the page
572543
lastNode.userNatron.addParam(param)
573-
574544
#Set param properties
575545
param.setHelp("Resultant Curve (keyframes)")
576546
param.setAddNewLine(True)
@@ -579,10 +549,8 @@ def createInstance(app,group):
579549
del param
580550

581551
param = lastNode.createButtonParam("resetCurves", "Reset curves")
582-
583552
#Add the param to the page
584553
lastNode.userNatron.addParam(param)
585-
586554
#Set param properties
587555
param.setHelp("Reset the curves to 0")
588556
param.setAddNewLine(False)
@@ -591,70 +559,65 @@ def createInstance(app,group):
591559
lastNode.resetCurves = param
592560
del param
593561

594-
# FFPLAY --------
595-
param = lastNode.createStringParam("viewerAudio", "Preview Viewer/Audio")
596-
param.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
597-
598-
#Add the param to the page
599-
lastNode.userNatron.addParam(param)
600-
601-
#Set param properties
602-
param.setHelp("")
603-
param.setAddNewLine(True)
604-
param.setEvaluateOnChange(False)
605-
param.setAnimationEnabled(False)
606-
lastNode.viewerAudio = param
607-
del param
608-
609-
param = lastNode.createButtonParam("playSync", "\u25b6")
610-
611-
#Add the param to the page
612-
lastNode.userNatron.addParam(param)
613-
614-
#Set param properties
615-
param.setHelp("Start a preview Viewer/Audio\nFor a good sync, Play/Cache the images in the viewer before start the preview")
616-
param.setAddNewLine(True)
617-
param.setPersistant(False)
618-
param.setEvaluateOnChange(False)
619-
param.setIconFilePath(os.path.dirname(os.path.realpath(__file__)) + "/play.png")
620-
lastNode.playSync = param
621-
del param
622-
623-
param = lastNode.createButtonParam("stopSync", "\u25a0")
624-
625-
#Add the param to the page
626-
lastNode.userNatron.addParam(param)
627-
628-
#Set param properties
629-
param.setHelp("Stop preview Viewer/Audio")
630-
param.setAddNewLine(False)
631-
param.setPersistant(False)
632-
param.setEvaluateOnChange(False)
633-
param.setIconFilePath(os.path.dirname(os.path.realpath(__file__)) + "/stop.png")
634-
lastNode.stopSync = param
635-
del param
636-
637-
param = lastNode.createStringParam("betterPreview", "For a good sync, play/cache the images\nin the viewer before start the preview")
638-
param.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
562+
# FFPLAY -------- Since find solution for 'backgrounded' ffplay on windows !!
563+
if not NatronEngine.natron.isWindows():
564+
param = lastNode.createStringParam("viewerAudio", "Preview Viewer/Audio")
565+
param.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
566+
#Add the param to the page
567+
lastNode.userNatron.addParam(param)
568+
#Set param properties
569+
param.setHelp("")
570+
param.setAddNewLine(True)
571+
param.setEvaluateOnChange(False)
572+
param.setAnimationEnabled(False)
573+
lastNode.viewerAudio = param
574+
del param
639575

640-
#Add the param to the page
641-
lastNode.userNatron.addParam(param)
642-
643-
#Set param properties
644-
param.setHelp("")
645-
param.setAddNewLine(False)
646-
param.setEvaluateOnChange(False)
647-
param.setAnimationEnabled(False)
648-
lastNode.betterPreview = param
649-
del param
650-
651-
# Create a tempfile within "ffplay pid"
652-
param = lastNode.createFileParam("tmpFile", "Temp File")
653-
param.setVisible(False)
654-
tf = tempfile.NamedTemporaryFile(delete=False)
655-
param.setDefaultValue(tf.name)
656-
lastNode.tmpFile = param
657-
del param
576+
param = lastNode.createButtonParam("playSync", "\u25b6")
577+
#Add the param to the page
578+
lastNode.userNatron.addParam(param)
579+
#Set param properties
580+
param.setHelp("Start a preview Viewer/Audio\nFor a good sync, Play/Cache the images in the viewer before start the preview")
581+
param.setAddNewLine(True)
582+
param.setPersistant(False)
583+
param.setEvaluateOnChange(False)
584+
param.setIconFilePath(os.path.dirname(os.path.realpath(__file__)) + "/audio2ascii/play.png")
585+
#param.setIconFilePath("audio2ascii/play.png") # decomment when Natron 2.0 stable is out
586+
lastNode.playSync = param
587+
del param
588+
589+
param = lastNode.createButtonParam("stopSync", "\u25a0")
590+
#Add the param to the page
591+
lastNode.userNatron.addParam(param)
592+
#Set param properties
593+
param.setHelp("Stop preview Viewer/Audio")
594+
param.setAddNewLine(False)
595+
param.setPersistant(False)
596+
param.setEvaluateOnChange(False)
597+
param.setIconFilePath(os.path.dirname(os.path.realpath(__file__)) + "/audio2ascii/stop.png")
598+
#param.setIconFilePath("audio2ascii/stop.png") # decomment when Natron 2.0 stable is out
599+
lastNode.stopSync = param
600+
del param
601+
602+
param = lastNode.createStringParam("betterPreview", "For a good sync, play/cache the images\nin the viewer before start the preview")
603+
param.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
604+
#Add the param to the page
605+
lastNode.userNatron.addParam(param)
606+
#Set param properties
607+
param.setHelp("")
608+
param.setAddNewLine(False)
609+
param.setEvaluateOnChange(False)
610+
param.setAnimationEnabled(False)
611+
lastNode.betterPreview = param
612+
del param
613+
614+
# Create a tempfile within "ffplay pid"
615+
param = lastNode.createFileParam("tmpFile", "Temp File")
616+
param.setVisible(False)
617+
tf = tempfile.NamedTemporaryFile(delete=False)
618+
param.setDefaultValue(tf.name)
619+
lastNode.tmpFile = param
620+
del param
658621
# /FFPLAY --------
659622

660623
# extra callback added

0 commit comments

Comments
 (0)