//mainly based off of openUtau lol
-const base_64_key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+const char *base64_key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-char *encode_pitch_array_base_64(int data[], int data_length) //from openUtau, rewritten;
+int encode_pitch_array_base_64(char buffer[],int data[], int data_length) //from openUtau, rewritten;
{
- char *result = malloc(data_length * sizeof(char) * 2);
- int last = NULL;
+
+ //char *result = malloc(data_length * sizeof(char) * 2);
+ //technically can take more than that if there's a number w/dups = 2
+ //eg: "AA#1#" is longer than "AAAA"
+ int last = -1;
int dups = 0;
int str_i = 0; //string index
-
- for (i = 0; i < data_length; i++) {
- char d = encode_int_to_base64(data[i]); //char[3], 3 == '\0'
-
- if (last == data[i]) {
- dups++;
- } else if (dups == 0) {
-
- //result[str_i] = d;
- result[str_i] = d[0];
- str_i++;
- result[str_i] = d[1];
- str_i++;
-
- } else {
-
- result[str_i] = '#';
- str_i++;
- result[str_i] =
-
-
+ if (buffer != NULL) {
+ for (int i = 0; i < data_length; i++) {
+ char *d = encode_int_to_base64(data[i]); //char[3], 3 == '\0'
+
+ if (last == data[i]) {
+ dups++;
+ } else if (dups == 0) {
+
+ //result[str_i] = d;
+ str_i += add_str_onto_str(d, &buffer[str_i]);
+
+ } else {
+
+ buffer[str_i] = '#';
+ str_i++;
+ char dups_string[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; //that should be enough :p
+ sprintf(dups_string, "%d", dups);
+ dups = 0;
+ str_i += add_str_onto_str(dups_string, &buffer[str_i]);
+ buffer[str_i] = '#';
+ str_i++;
+ str_i += add_str_onto_str(d, &buffer[str_i]);
+ };
+ last = data[i];
+
+ };
+ buffer[str_i] = '\0';
+ } else {
+ for (int i = 0; i < data_length; i++) {
+ char *d = encode_int_to_base64(data[i]); //char[3], 3 == '\0'
+
+ if (last == data[i]) {
+ dups++;
+ } else if (dups == 0) {
+
+ //result[str_i] = d;
+ str_i += 2;
+
+ } else {
+ str_i++;
+ str_i += snprintf(NULL, 0, "%d", dups);
+ dups = 0;
+ str_i++;
+ str_i += 2;
+ };
+ last = data[i];
+
+ };
};
- return result;
+
+ return str_i + 1;
};
char *encode_int_to_base64(int i) //basically entirely from open utau ww
{
if (i < 0) {
- data += 4096;
+ i += 4096;
}; //no idea why buy openutau does that haha
char *base_64 = "AA";
- base_64[0] = base64_key[(data >> 6) & 0x003F];
- base_64[1] = base64_key[data & 0x003F];
+ base_64[0] = base64_key[(i >> 6) & 0x003F];
+ base_64[1] = base64_key[i & 0x003F];
return base_64;
};
//the main file UwU
-void main(int argc, char *argv[])
+int main(int argc, char *argv[])
{
- //colon3utau [render] [arguments]
+ //colon3utau [render|--version|] [arguments]
+
+ if (argc == 1) {
+ //print_Help();
+ return 0;
+ };
+
+ //printf(argv[1]);
+ if (strcmp(argv[1], "render") == 0) {
+ //render
+ Render(argc, argv);
+ } else if (strcmp(argv[1], "cheese") == 0) {
+ //cheese
+ printf("I want to cheese.");
+ } else if (strcmp(argv[1], "--version")) {
+ //version
+ printf("version 0.1, parking_turkeys");
+ } else {
+ printf("Command not recognized.");
+ };
+
+ return 0;
+
+};
--- /dev/null
+//rendering main part
+#include "render.h"
+
+#define MAX_TOOL_PATH 1024
+
+//modes for reading the UST
+
+int Render(int argc, char *argv[])
+{
+ /* colon3utau render <ust> [options] */
+ /* options:
+ * --ask (default): ask for filepaths
+ * (nothing else is implemented LOL)
+ * (config files soon[tm])
+ *
+ */
+
+ char *USTpath = argv[2];
+
+
+ //this is the --ask part
+ char *wavtool_path = malloc(MAX_TOOL_PATH);
+ char *resampler_path = malloc(MAX_TOOL_PATH);
+ char *voicebank_path = malloc(MAX_TOOL_PATH);
+
+ printf("Default wavtool path: %s\n", DEFAULT_WAVTOOL);
+ ask_for_input("Enter path to wavtool:", wavtool_path, MAX_TOOL_PATH);
+
+ printf("Default resampler path: %s\n", DEFAULT_RESAMPLER);
+ ask_for_input("Enter path to resampler:", resampler_path, MAX_TOOL_PATH);
+
+ printf("Default voicebank path: %s\n", DEFAULT_VOICEBANK); //this should really show the UST info
+ ask_for_input("Enter path to voicebank:", voicebank_path, MAX_TOOL_PATH);
+
+
+ //next, process the UST
+
+
+ return 1;
+};
+
+
--- /dev/null
+//header for rendering ig??
+
+#include "../utau.h"
+
+/* defines */
+
+//default paths--these should never be used in prod lol
+//voicebank should be the folder containing character.txt
+#define DEFAULT_WAVTOOL "D:\\applications\\utau\\wavtool.exe"
+#define DEFAULT_RESAMPLER "D:\\applications\\utau\\resampler.exe"
+#define DEFAULT_VOICEBANK "D:\\applications\\utau\\voice\\uta"
+
+
+
+/* functions */
+
+//ust_process.c
+int process_ust(char *wavtool_path, char *resampler_path, char *voicebank_path,
+ char *UST_path);
+
+//wavtool.c
+int call_wavtool(char *wavtool_path, struct USTinfo *ust_settings, struct
+ USTnote *note, char *oto_path);
+
+//resampler.c
+int call_resampler(char *resampler_path, struct USTinfo *ust_settings, struct
+ USTnote *note, char *oto_path);
+
+
+
+
+
+
+
+
+/* useful functions from utau.h
+ *
+ * int encode_pitch_array_base_64(char buffer[],int data[], int data_length);
+ * char *encode_int_to_base64(int input);
+ * char *ask_for_input(char *prompt); //DO NOT FREE RETURNED MEMORY
+ *
+ */
+
+
+
+
--- /dev/null
+#include "render.h"
+
+#define MODE_HEADING 1
+#define MODE_NEW_LINE 2
+#define MODE_KEY 3
+#define MODE_VAL 4
+#define MODE_SKIPLINE 5
+
+
+#define HEADING_VERSION 10
+#define HEADING_SETTINGS 11
+#define HEADING_NOTE 12
+
+static int mode = MODE_NEW_LINE;
+static int curr_heading = 0;
+
+
+
+static int add_ust_setting (FILE *fp, USTinfo *UST );
+static int add_note_setting(FILE *fp, USTnote *note);
+
+int process_ust(char *wavtool, char *resampler, char *voice, char *UST)
+{
+ FILE *fp;
+ fp = fopen(UST, "r");
+
+ char c;
+ int i = 0;
+ char buffer[256];
+ struct USTnote *curr_note;
+ *curr_note = (struct USTnote) {
+ 0,
+ NULL,
+ 60,
+ NULL,
+ 0,
+ 0,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+
+ };
+
+ struct USTinfo *settings;
+ *settings = (struct USTinfo){
+ 120.0,
+ 1,
+ "New Project",
+ voice,
+ "cache",
+ wavtool,
+ resampler,
+ 1
+ };
+
+ while ((true) && ((c = getc(fp)) != EOF)) {
+
+ switch (mode) {
+ case MODE_NEW_LINE:
+ switch (c) {
+ case '[':
+ mode = MODE_HEADING;
+ break;
+ case '\n'
+ break;
+ default:
+ fseek(fp, -1, SEEK_CUR);
+ switch (curr_heading) {
+ case HEADING_VERSION:
+ break;
+ case HEADING_SETTINGS:
+ add_ust_setting(fp, settings);
+ break;
+ case HEADING_NOTE:
+ add_note_setting(fp, curr_note);
+ break;
+ default:
+ break;
+ };
+ break;
+ };
+ break;
+ case MODE_HEADING:
+ switch (c) {
+ case '#':
+ break;
+ case '\n':
+ mode = MODE_NEW_LINE;
+ break;
+ case ']':
+ buffer[i] = '\0';
+ if (strcmp(buffer, "VERSION") == 0) {
+ curr_heading = HEADING_VERSION;
+ } else if (strcmp(buffer, "SETTING") == 0) {
+ curr_heading = HEADING_SETTINGS;
+ } else if (strcmp(buffer, "TRACKEND") == 0) {
+ //do nothing
+ } else {
+ curr_heading = HEADING_NOTE;
+ if (curr_note) {
+ process_note(curr_note, USTinfo);
+ };
+ };
+ break;
+ default:
+ buffer[i++] = c;
+ break;
+ };
+ break;
+ default:
+ printf("v strange error, why is mode not what it should be?? (ust_process.c)");
+ break;
+ };
+ };
+
+ return 1;
+};
+
+static int process_keyval(FILE *fp, char *key, char *value);
+
+int add_ust_setting(FILE *fp, USTinfo *u)
+{
+ char key[128];
+ char value[2048];
+
+ process_keyval(fp, key, value);
+
+ if (same(key, "Tempo")) {
+ u->tempo = arg_to_float(value);
+ } else if (same(key, "Tracks")) {
+ u->tracks = (int)arg_to_float(value);
+ } else if (same(key, "ProjectName")) {
+ //i dont feel like dealing with this haha
+ } else if (same(key, "Mode2")) {
+ u->mode2 = (int)arg_to_float(value);
+ } else if (same(key, "CacheDir")) {
+ //u->cachedir = //too lazy :p
+ };
+ return 1;
+};
+
+int process_pitch_list_float(float stuff[], char *list);
+int process_pitch_list_char (char stuff[], char *list);
+float *process_envelope_list(char *list);
+
+int add_note_setting(FILE *fp, USTnote *n)
+{
+ char key[128];
+ char value[2048];
+ static char lyric[64];
+ static float PBS[256];
+ static float PBW[256];
+ static float PBY[256];
+ static char PBM[256]; //too many but just in case lol
+ static float VBR[8];
+ static char flags[2048];
+ //all static because every setting will only be added once before the note is played (==unneeded)
+
+
+ process_keyval(fp, key, value);
+
+ if (same(key, "Length")) {
+ n->length = (int)arg_to_float(value);
+ } else if (same(key, "Lyric")) {
+ for (int i = 0; (lyric[i] = value[i]) != '\0'; i++) {};
+ n->lyric = lyric;
+ } else if (same(key, "NoteNum")) {
+ n->midinote = (int)arg_to_float(value);
+ } else if (same(key, "Envelope")) {
+ n->midinote = process_envelope_list(value);
+ } else if (same(key, "PBS")) {
+ n->PBSlength = process_pitch_list_float(PBS, value);
+ } else if (same(key, "PBW")) {
+ n->PBWlength = process_pitch_list_float(PBW, value);
+ } else if (same(key, "PBY")) {
+ n->PBYlength = process_pitch_list_float(PBY, value);
+ } else if (same(key, "PBM")) {
+ n->PBMlength = process_pitch_list_char(PBM, value);
+ } else if (same(key, "STP")) {
+ n->STP = arg_to_float(value);
+ } else if (same(key, "VBR")) {
+ process_pitch_list_float(VBR, value);
+ n->VBR = VBR;
+ } else if (same(key, "PreUtterance")) {
+ if (value != "") {
+ n->preutterance = arg_to_float(value);
+ } else {
+ n->preutterance = NULL;
+ };
+ } else if (same(key, "Intensity")) {
+ n->intensity = (int)arg_to_float(value);
+ } else if (same(key, "Modulation")) {
+ n->modulation = arg_to_float(value);
+ } else if (same(key, "Flags")) {
+ for (int i = 0; (flags[i] = value[i]) != '\0'; i++) {};
+ n->flags = flags;
+ } else if (same(key, "Velocity")) {
+ n->velocity = arg_to_float(value);
+ } else if (same(key, "VoiceOverlap")) {
+ n->overlap = arg_to_float(value);
+ };
+
+ return 1;
+
+};
+
+
+
+
+
+
//from here [colon3utau]
-void add_str_onto_str(char *input, char *output)
+int add_str_onto_str(char *input, char *output)
{
char c = ' ';
- for (int i = 0; ((c = input[i]) != '\0') && (output[i] != '\0'); i++) {
+ int i = 0;
+ while ((++i) && ((c = input[i]) != '\0') && (output[i] != '\0')) {
output[i] = c;
};
- return;
+
+ return i;
+};
+
+
+int ask_for_input(char *prompt, char *buffer, int INPUT_MAX) //intended for paths
+{
+ printf(prompt);
+ int i = 0;
+ while ((i < (INPUT_MAX - 3) ) && ((buffer[i++] = getc(stdin)) != '\n')) {};
+ buffer[i] = '\0';
+ putc('\n', stdout);
+ return 1;
};
+
+int same(char *a, char *b)
+{
+ char ac, bc;
+ int i;
+ while (((ac = a[i]) != '\0') && ((bc = b[i]) != '\0')) {
+ if (ac != bc) {
+ return 0;
+ };
+ i++;
+ };
+ return 1;
+};
+
*
*/
+/* INCLUDES */
+
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
+
/* FUNCTIONS */
+/* functions noted with "malloc()" require the returned value to be free()d */
//useful.c
float length_arg_to_float(char *arg);
float arg_to_float(char *arg);
int report_error(char *msg, char *portion, char *program);
-void add_str_onto_str(char *input, char *output);
+int add_str_onto_str(char *input, char *output);
+char *ask_for_input(char *prompt); //DO NOT FREE RETURNED MEMORY, USE IMMEDIATELY
+int same(char *a, char *b);
//base64.c
-char *encode_pitch_array_base_64(int data[], int data_length);
-char *encode_int_to_base64(int i);
+int encode_pitch_array_base_64(char buffer[],int data[], int data_length);
+char *encode_int_to_base64(int input);
//render
int Render(int argc, char *argv[]);
+
+
+/* STRUCTS */
+
+struct USTinfo {
+ float tempo;
+ int tracks; //unimportant?
+ char *name;
+ char *voicedir; //starts with %VOICE% generally
+ //char *outfile; //seems actually unimportant lol
+ char *cachedir; //relative to UST
+ char *wavtool; //path
+ char *resampler; //path
+ int mode2; //true|false
+};
+
+struct USTnote {
+ int length;
+ char *lyric;
+ int midinote;
+ float envelope[10]; (excluding %)
+ float overlap;
+ float velocity;
+ float preutterance; //ALWAYS THERE even if blank
+ char *flags;
+ float STP;
+ float VBR[8];
+ float PBS[];
+ int PBSlength;
+ float PBW[];
+ int PBWlength;
+ float PBY[];
+ int PBYlength;
+ char PBM[];
+ int PBMlength;
+ int intensity;
+ float modulation;
+};
+
+
+typedef struct {
+ float x;
+ float y;
+} Vector2;
+
+typedef struct pitchpoint {
+ Vector2 v;
+ int shape; //not sure what ts is, it's from openUtau loll
+} PitchPoint;
+