changeset 229:c768ed1055b0 mergingClockSync

Fixed heavy-midi and updated uploader.py
author Giulio Moro <giuliomoro@yahoo.it>
date Sat, 09 Apr 2016 00:52:57 +0100
parents a0a7f00cf98d
children af211ee57867
files scripts/hvresources/render.cpp scripts/hvresources/uploader.py
diffstat 2 files changed, 67 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/hvresources/render.cpp	Fri Apr 08 22:26:44 2016 +0100
+++ b/scripts/hvresources/render.cpp	Sat Apr 09 00:52:57 2016 +0100
@@ -127,16 +127,16 @@
 					float velocity = message.getDataByte(1);
 					float channel = message.getChannel();
 //					rt_printf("message: noteNumber: %f, velocity: %f, channel: %f\n", noteNumber, velocity, channel);
-					hv_vscheduleMessageForReceiver(gHeavyContext, "hv_notein", 0, "fff", noteNumber, velocity, channel);
+					hv_vscheduleMessageForReceiver(gHeavyContext, "bela_notein", 0, "fff", noteNumber, velocity, channel);
 				}
 				break;
 			case kmmControlChange: {
-				hv_vscheduleMessageForReceiver(gHeavyContext, "hv_ctlin", 0, "fff",
+				hv_vscheduleMessageForReceiver(gHeavyContext, "bela_ctlin", 0, "fff",
 						(float)message.getDataByte(1), (float)message.getDataByte(0), (float)message.getChannel());
 				}
 				break;
 			case kmmProgramChange:
-				hv_vscheduleMessageForReceiver(gHeavyContext, "hv_pgmin", 0, "ff",
+				hv_vscheduleMessageForReceiver(gHeavyContext, "bela_pgmin", 0, "ff",
 						(float)message.getDataByte(0), (float)message.getChannel());
 				break;
 			}
--- a/scripts/hvresources/uploader.py	Fri Apr 08 22:26:44 2016 +0100
+++ b/scripts/hvresources/uploader.py	Sat Apr 09 00:52:57 2016 +0100
@@ -1,6 +1,4 @@
-#!/usr/bin/python
-
-# Copyright 2015 Section6. All Rights Reserved.
+# Copyright 2015,2016 Enzien Audio, Ltd. All Rights Reserved.
 
 import argparse
 import getpass
@@ -13,7 +11,6 @@
 import time
 import urlparse
 import zipfile
-import sys
 
 class Colours:
     purple = "\033[95m"
@@ -47,19 +44,27 @@
         description="Compiles a Pure Data file.")
     parser.add_argument(
         "input_dir",
-        help="A directory containing _main.pd. The entire directory will be uploaded.")
+        help="A directory containing _main.pd. All .pd files in the directory structure will be uploaded.")
     parser.add_argument(
         "-n", "--name",
         default="heavy",
-        help="Patch name. If it doesn't exist, the uploader will fail. Make sure that it exists on the Heavy website.")
+        help="Patch name. If it doesn't exist on the Heavy site, the uploader will fail.")
     parser.add_argument(
         "-g", "--gen",
         nargs="+",
         default=["c"],
-        help="List of generator outputs. Currently supported generators are 'c' and 'js'.")
+        help="List of generator outputs. Currently supported generators are "
+            "'c', 'js', 'pdext', 'pdext-osx', 'unity', 'unity-osx', "
+            "'unity-win-x86', 'unity-win-x86_64', 'wwise', 'wwise-win-x86_64', "
+            "'vst2' ,'vst2-osx', and 'vst2-win-x86_64'.")
     parser.add_argument(
         "-b",
-        help="All files will be placed in the output directory, placed in their own subdirectory corresonding to the generator name.",
+        help="All files will be placed in the output directory, placed in their own subdirectory corresponding to the generator name.",
+        action="count")
+    parser.add_argument(
+        "-y",
+        help="Extract only the generated C files. Static files are deleted. "
+            "Only effective for the 'c' generator.",
         action="count")
     parser.add_argument(
         "-o", "--out",
@@ -80,12 +85,16 @@
         action="count")
     parser.add_argument(
         "--noverify",
-        help="Don't verify the SSL connection. Generally a bad idea.",
+        help="Don't verify the SSL connection. This is generally a very bad idea.",
         action="count")
     parser.add_argument(
         "-v", "--verbose",
         help="Show debugging information.",
         action="count")
+    parser.add_argument(
+        "-t", "--token",
+        help="Use the specified token.",
+    )
     args = parser.parse_args()
 
     domain = args.domain or "https://enzienaudio.com"
@@ -94,11 +103,14 @@
 
     # token should be stored in ~/.heavy/token
     token_path = os.path.expanduser(os.path.join("~/", ".heavy", "token"))
-    if os.path.exists(token_path) and not args.z:
+
+    if args.token is not None:
+        # check if token has been passed as a command line arg...
+        post_data["credentials"] = {"token": args.token}
+    elif os.path.exists(token_path) and not args.z:
+        # ...or if it is stored in the user's home directory
         with open(token_path, "r") as f:
-            post_data["credentials"] = {
-                "token": f.read()
-            }
+            post_data["credentials"] = {"token": f.read()}
     else:
         # otherwise, get the username and password
         post_data["credentials"] = {
@@ -127,7 +139,13 @@
     post_data["name"] = args.name
 
     # the outputs to generate (always include c)
-    __SUPPORTED_GENERATOR_SET = {"c", "js"}
+    __SUPPORTED_GENERATOR_SET = {
+        "c", "js",
+        "pdext", "pdext-osx",
+        "unity", "unity-osx", "unity-win-x86", "unity-win-x86_64",
+        "wwise", "wwise-win-x86_64",
+        "vst2", "vst2-osx", "vst2-win-x86_64",
+    }
     post_data["gen"] = list(({"c"} | set(args.gen)) & __SUPPORTED_GENERATOR_SET)
 
     # upload the job, get the response back
@@ -141,6 +159,7 @@
 
     if r.status_code != requests.codes.ok:
         shutil.rmtree(temp_dir) # clean up the temporary directory
+        print "Getting a weird error? Get the latest uploader at https://enzienaudio.com/static/uploader.py"
         r.raise_for_status() # raise an exception
 
     # decode the JSON API response
@@ -193,7 +212,9 @@
           "type": "file"
         }
       ],
-      "warnings": [],
+      "warnings": [
+        {"details": "blah blah blah"}
+      ],
       "meta": {
         "token": "11AS0qPRmjTUHEMSovPEvzjodnzB1xaz"
       }
@@ -209,22 +230,32 @@
 
     # update the api token, if present
     if "token" in reply_json.get("meta",{}) and not args.x:
-        if not os.path.exists(os.path.dirname(token_path)):
-            os.makedirs(os.path.dirname(token_path)) # ensure that the .heavy directory exists
-        with open(token_path, "w") as f:
-            f.write(reply_json["meta"]["token"])
-        os.chmod(token_path, stat.S_IRUSR | stat.S_IWUSR) # force rw------- permissions on the file
+        if args.token is not None:
+            if reply_json["meta"]["token"] != args.token:
+                print "WARNING: Token returned by API is not the same as the "
+                "token supplied at the command line. (old = %s, new = %s)".format(
+                    args.token,
+                    reply_json["meta"]["token"])
+        else:
+            if not os.path.exists(os.path.dirname(token_path)):
+                # ensure that the .heavy directory exists
+                os.makedirs(os.path.dirname(token_path))
+            with open(token_path, "w") as f:
+                f.write(reply_json["meta"]["token"])
+            # force rw------- permissions on the file
+            os.chmod(token_path, stat.S_IRUSR | stat.S_IWUSR)
 
     # print any warnings
-    for x in r_json["warnings"]:
-        print "{0}Warning:{1} {2}".format(Colours.yellow, Colours.end, x["detail"])
+    for i,x in enumerate(r_json.get("warnings",[])):
+        print "{3}) {0}Warning:{1} {2}".format(
+            Colours.yellow, Colours.end, x["detail"], i+1)
 
     # check for errors
     if len(r_json.get("errors",[])) > 0:
         shutil.rmtree(temp_dir) # clean up the temporary directory
-        for x in r_json["errors"]:
-            print "{0}Error:{1} {2}".format(Colours.red, Colours.end, x["detail"])
-        sys.exit(1)
+        for i,x in enumerate(r_json["errors"]):
+            print "{3}) {0}Error:{1} {2}".format(
+                Colours.red, Colours.end, x["detail"], i+1)
         return
 
     # retrieve all requested files
@@ -251,6 +282,12 @@
                 os.makedirs(target_dir) # ensure that the output directory exists
             __unzip(c_zip_path, target_dir)
 
+            if g == "c" and args.y:
+                keep_files = ("_{0}.h".format(args.name), "_{0}.c".format(args.name))
+                for f in os.listdir(target_dir):
+                    if not f.endswith(keep_files):
+                        os.remove(os.path.join(target_dir, f));
+
             print "{0} files placed in {1}".format(g, target_dir)
         else:
             print "{0}Warning:{1} {2} files could not be retrieved.".format(
@@ -260,10 +297,9 @@
     # delete the temporary directory
     shutil.rmtree(temp_dir)
 
-    print "Job URL", reply_json["data"]["links"]["self"]
+    print "Job URL:", reply_json["data"]["links"]["self"]
     print "Total request time: {0}ms".format(int(1000.0*(time.time()-tick)))
-
-    sys.exit(0)
+    print "Heavy version:", reply_json["meta"]["version"]
 
 def __get_file_url_for_generator(json_api, g):
     """Returns the file link for a specific generator.