]> _ Git - colon3wavtool.git/commitdiff
Rests!! (next: the thing. where like. notes start earlier idk)
authorparking_turkeys <roya1060wien@gmail.com>
Fri, 14 Aug 2026 18:23:04 +0000 (14:23 -0400)
committerparking_turkeys <roya1060wien@gmail.com>
Fri, 14 Aug 2026 18:23:04 +0000 (14:23 -0400)
main.c
readwave.c
useful.c [new file with mode: 0644]
wavtool.h

diff --git a/main.c b/main.c
index f4ead24..ac298e7 100644 (file)
--- a/main.c
+++ b/main.c
@@ -7,6 +7,7 @@
  */
 
 #include "wavtool.h"
+#include <math.h>
 
 #define LOGFILE L"C:\\projects\\colon3wavtool\\log.txt"
 
@@ -31,8 +32,15 @@ int main(int argc, char *argv[])
        if (input_wave_length > 0) {
                input_wave = GlobalAlloc(0, input_wave_length);
        } else { 
+               /* expected for rests
                error_msg = "input wave error || input wave length is 0";
                goto error; 
+               */
+               //MessageBox(NULL, argv[4], "rest length", MB_OK);
+               input_wave_length = ceil(44100 * length_arg_to_float(argv[4]) * 2);
+               printf("%d", input_wave_length);
+               input_wave = GlobalAlloc(GPTR,input_wave_length);//initializes to 0
+               //not working?! //got the wrong argument...
        }
        int errored = 0;
        if (input_wave != NULL) {
@@ -69,6 +77,8 @@ int log_args(int argc, char *argv[])
        //0: program path (obviously)
        //1: some temp.wav to append the note to (relative. it doesnt exist at first)
        //2: note wav file (full, not relative)
+       //3: stp, the time (in ms) the note should be shifted left (instead of just appending it uwu)
+       //4: length, the length of the note (in ms)
        //3-end: some envelope shit idk. Unimportant probably /j
 
 
index a90a2e2..38224ed 100644 (file)
@@ -19,8 +19,12 @@ int readWave(char *filename, int16_t buffer[]) //if buffer is NULL it only retur
                        );
 
        if (fp == INVALID_HANDLE_VALUE) {
+               /* UTAU has rests setup as simply notes with no file so you cant fail here
+                * instead we will add rest by making like blank. uwu? or no just return 0 and make main do it.
                error_msg = "error opening input wave file";
                goto error;
+               */
+               return 0;
        };
 
        //get file length and load it ig...
diff --git a/useful.c b/useful.c
new file mode 100644 (file)
index 0000000..da3e3f9
--- /dev/null
+++ b/useful.c
@@ -0,0 +1,100 @@
+#include "wavtool.h"
+
+
+float length_arg_to_float(char *arg)
+{
+       //formatted in a weird af way
+       //from looking at other ppls code (gh/m13253/wavtool-yawu) + what i can tell:
+       //it is
+       //x@y[+-]z
+       //x == "ticks" (in yawu code) (idk what this means tbh) [INT] [POSSIBLY FLOAT?]
+       //y == tempo [INT] [UNLESS TEMPO IS FLOAT]
+       //z == divided by 1000 and then added to note_length in yawu.. (yes im just basing it off of there i cant figure ts out :((()
+       //so yawu finds note_length by ticks/tempo/8, and note_length seems to be in ... idk tbh LMAO
+       //uhh idk what a tick is tbh but for my (1/4) rest note ticks = 480 and tempo = 120 (z = 19.0)
+       //480/120/8 = 4/8 = 1/2
+       //ok for a full rest (4/4) it's 1920@120-71.0
+       //that's 1920/120/8 = 16/8 = 2
+       // so a 1/4 note is 1/2, a 4/4 note is 2, a 1/2 note is presumably 1
+       //in 120 tempo
+       //when in 120 tempo thats uhh 2 1/4 a second  i think
+       //so that answer is in SECONDS. yay.
+       //and just adding the second part in i guess... shouldnt it be minused??
+       //actually no idea why the second part exists so im skipping it for now lmao
+       //tyty yawu code author. otherwise i would be COOKED
+       int i = 0;
+       char c = 'x';
+       char buffer[50] = {'\0'}; //who is making smth with a longer number tbh
+       int b_i = 0;
+
+       float x = 0;
+       float y = 0;
+       float z = 0;
+
+       float sign = 1.0; //-1.0 for negative uwu
+
+       while ((c = arg[i++]) != '\0') {
+               switch (c) {
+                       case '@':
+                               //first break
+                               x = arg_to_float(buffer);
+                               b_i = 0;
+                               break;
+                       case '+':
+                               //second break :p
+                               y = arg_to_float(buffer);
+                               b_i = 0;
+                               break;
+                       case '-':
+                               //second break but NEGATIVE
+                               y = arg_to_float(buffer);
+                               b_i = 0;
+                               sign = -1.0;
+                               break;
+                       case '\0':
+                               //end
+                               z = sign * arg_to_float(buffer);
+                               b_i = 0;
+                               break;
+                       default:
+                               buffer[b_i] = c;
+                               b_i ++;
+                               buffer[b_i] = '\0';
+                               break;
+               };
+                                               
+       };
+       z = sign * arg_to_float(buffer);
+       return x/y/8 + z/1000;
+};
+
+float arg_to_float(char *arg)
+{
+       //get digit from ascii by subtracting 48
+       char c;
+       float r = 0.0; //result
+       int d = 0; //i of decimal point if after decimal point
+       int i = 0;
+       while ((c = arg[i++]) != '\0') {
+               switch (c) {
+               case '.':
+                       //decimal point
+                       d = i;
+                       break;
+               default:
+                       //must be a digit
+                       if (!d) {
+                               r = r * 10.0;
+                               r += (float)c - 48.0;
+                       } else {
+                               float t = (float)c - 48.0;
+                               for (int n = 0; n <= (i - d); n++) {
+                                       t = t/10;
+                               };
+                               r += t;
+                       };
+                       break;
+               };
+       };
+       return r;
+};
index 7c010d0..71077b1 100644 (file)
--- a/wavtool.h
+++ b/wavtool.h
@@ -16,6 +16,9 @@ struct riff_chunk {
        uint32_t ckSize;
        uint8_t ckData[];//length == ckSize
 };
+//useful shit
+float arg_to_float(char *arg);
+float length_arg_to_float(char *arg); //returns float of SECONDS. >:(
 
 //ok so first read the whole file into a thingy
 int readWave(char *filename, int16_t buffer[]);