Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
5.3KB

  1. #! /usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. PyNSMClient - A New Session Manager Client-Library in one file.
  5. The Non-Session-Manager by Jonathan Moore Liles <male@tuxfamily.org>: http://non.tuxfamily.org/nsm/
  6. New Session Manager by Nils Hilbricht et al https://new-session-manager.jackaudio.org
  7. With help from code fragments from https://github.com/attwad/python-osc ( DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE v2 )
  8. MIT License
  9. Copyright (c) since 2014: Laborejo Software Suite <info@laborejo.org>, All rights reserved.
  10. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
  11. associated documentation files (the "Software"), to deal in the Software without restriction,
  12. including without limitation the rights to use, copy, modify, merge, publish, distribute,
  13. sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
  14. furnished to do so, subject to the following conditions:
  15. The above copyright notice and this permission notice shall be included in all copies or
  16. substantial portions of the Software.
  17. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
  18. NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  20. DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
  21. OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. """
  23. from time import sleep # main event loop at the bottom of this file
  24. # nsm only
  25. from nsmclient import NSMClient # will raise an error and exit if this example is not run from NSM.
  26. ########################################################################
  27. # General
  28. ########################################################################
  29. niceTitle = "myNSMprogram" # This is the name of your program. This will display in NSM and can be used in your save file
  30. ########################################################################
  31. # Prepare the NSM Client
  32. # This has to be done as the first thing because NSM needs to get the paths
  33. # and may quit if NSM environment var was not found.
  34. #
  35. # This is also where to set up your functions that react to messages from NSM,
  36. ########################################################################
  37. # Here are some variables you can use:
  38. # ourPath = Full path to your NSM save file/directory with serialized NSM extension
  39. # ourClientNameUnderNSM = Your NSM save file/directory with serialized NSM extension and no path information
  40. # sessionName = The name of your session with no path information
  41. ########################################################################
  42. def saveCallback(ourPath, sessionName, ourClientNameUnderNSM):
  43. # Put your code to save your config file in here
  44. print("saveCallback");
  45. def openCallback(ourPath, sessionName, ourClientNameUnderNSM):
  46. # Put your code to open your config file in here
  47. print("openCallback");
  48. def exitProgram(ourPath, sessionName, ourClientNameUnderNSM):
  49. """This function is a callback for NSM.
  50. We have a chance to close our clients and open connections here.
  51. If not nsmclient will just kill us no matter what
  52. """
  53. print("exitProgram");
  54. # Exit is done by NSM kill.
  55. def showGUICallback():
  56. # Put your code that shows your GUI in here
  57. print("showGUICallback");
  58. nsmClient.announceGuiVisibility(isVisible=True) # Inform NSM that the GUI is now visible. Put this at the end.
  59. def hideGUICallback():
  60. # Put your code that hides your GUI in here
  61. print("hideGUICallback");
  62. nsmClient.announceGuiVisibility(isVisible=False) # Inform NSM that the GUI is now hidden. Put this at the end.
  63. nsmClient = NSMClient(prettyName = niceTitle,
  64. saveCallback = saveCallback,
  65. openOrNewCallback = openCallback,
  66. showGUICallback = showGUICallback, # Comment this line out if your program does not have an optional GUI
  67. hideGUICallback = hideGUICallback, # Comment this line out if your program does not have an optional GUI
  68. supportsSaveStatus = False, # Change this to True if your program announces it's save status to NSM
  69. exitProgramCallback = exitProgram,
  70. loggingLevel = "info", # "info" for development or debugging, "error" for production. default is error.
  71. )
  72. # If NSM did not start up properly the program quits here.
  73. ########################################################################
  74. # If your project uses JACK, activate your client here
  75. # You can use jackClientName or create your own
  76. ########################################################################
  77. jackClientName = nsmClient.ourClientNameUnderNSM
  78. ########################################################################
  79. # Start main program loop.
  80. ########################################################################
  81. # showGUICallback() # If you want your GUI to be shown by default, uncomment this line
  82. print("Entering main loop")
  83. while True:
  84. nsmClient.reactToMessage() # Make sure this exists somewhere in your main loop
  85. # nsmClient.announceSaveStatus(False) # Announce your save status (dirty = False / clean = True)
  86. sleep(0.05)