Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Any C programmers wanna help convert code to convert between MIDI + CSV?
#11
Shocked 
(08-26-2022, 02:54 AM)madscijr Wrote: :Might you be the expert we're looking for? 
:-D
Yes, while I used Power C by Mix Software from Richardson, Texas. But this was a few decades ago, without hard disk, VGA, USB, high-speed Internet, live MP3/MP4/OGG/OGV playback and too much we take for granted now.
Reply
#12
(08-26-2022, 03:35 AM)mnrvovrfc Wrote:
(08-26-2022, 02:54 AM)madscijr Wrote: :Might you be the expert we're looking for? 
:-D
Yes, while I used Power C by Mix Software from Richardson, Texas. But this was a few decades ago, without hard disk, VGA, USB, high-speed Internet, live MP3/MP4/OGG/OGV playback and too much we take for granted now.

I remember those days, back when computer storage meant a cassette tape, and getting a 5.25" floppy drive felt like a serious upgrade. 

I have gone back to code I wrote on a Commodore 64 in the Reagan years, and I remembered more than I thought I would!
Reply
#13
Is this why you wanted info about C compilers, IDEs, etc?


Ugh, that's pretty densely packed C, so conversion to a different language might take a minute or three and induce a few headaches.

Unguarded, unblocked multi-statement lines following for() statements?.  Good God why?  That's a invitation for bugs.  Thankfully GCC complains about that.

Anyway, I can't help on a conversion project at this time, but I edited the C sources which allow them to compile without error using QB64PE's bundled MinGW compiler.

I assumed those multi-statement lines were supposed to be blocks and treated them as such, blocking them up nice & neat for compilation.  Hopefully this doesn't break functionality.

They both run well enough to display a list of options when run from the command line, but I have no MIDI files to test them on, so no guarantees that they will be bug-free.  You will have to test it.

Zip file attached which includes original source from your post, compileable source, and MinGW-compiled Windows 32-bit executables.  That compilable source includes a batch file to automate compilation using QB64's bundled MinGW.


(@mnrvovrfc : I heard a lot of good things about Power C back in the day, and Mix Software is still out there selling Power C for DOS!  I started out with James E. Hendrix's Small C, myself.  Good times!)


Attached Files
.zip   MADSCIJR_MIDI_TO_CSV.zip (Size: 45.89 KB / Downloads: 41)
Reply
#14
(08-26-2022, 04:24 AM)JRace Wrote: Is this why you wanted info about C compilers, IDEs, etc?


Ugh, that's pretty densely packed C, so conversion to a different language might take a minute or three and induce a few headaches.

Unguarded, unblocked multi-statement lines following for() statements?.  Good God why?  That's a invitation for bugs.  Thankfully GCC complains about that.

Anyway, I can't help on a conversion project at this time, but I edited the C sources which allow them to compile without error using QB64PE's bundled MinGW compiler.

I assumed those multi-statement lines were supposed to be blocks and treated them as such, blocking them up nice & neat for compilation.  Hopefully this doesn't break functionality.

They both run well enough to display a list of options when run from the command line, but I have no MIDI files to test them on, so no guarantees that they will be bug-free.  You will have to test it.

Zip file attached which includes original source from your post, compileable source, and MinGW-compiled Windows 32-bit executables.  That compilable source includes a batch file to automate compilation using QB64's bundled MinGW.


(@mnrvovrfc : I heard a lot of good things about Power C.  I started out with James E. Hendrix's Small C, myself.  Good times!)

Well thank you! I shall give this a go. Moving us a little further along. 

PS Some MIDI files for you 
https://freemidi.org/artist-465-frank-zappa
Reply
#15
@JRace
@TempodiBasic
@mnrvovrfc
@bplus
@Jack
@Kernelpanic
(08-26-2022, 04:24 AM)JRace Wrote: Ugh, that's pretty densely packed C, so conversion to a different language might take a minute or three and induce a few headaches.
Unguarded, unblocked multi-statement lines following for() statements?.  Good God why?  That's a invitation for bugs.  Thankfully GCC complains about that.
...
Zip file attached which includes original source from your post, compileable source, and MinGW-compiled Windows 32-bit executables.  That compilable source includes a batch file to automate compilation using QB64's bundled MinGW.

With your help and batch file, I got it compiling and it runs.
(So first I want to say thank you to all you guys for helping me get that working!)

Now for the MIDI conversion... 

PHASE 1
Using a free online MIDI composer at I created a simple test MIDI file with a simple song 
(only 1 instrument/track) "mary had a little lamb",
and downloaded it, named "mary1.mid".

mid2asc did convert a MIDI file to a text file named "mary2.txt",
but something must be off in the code, 
because when I tried converting it back to MIDI "mary3.mid"
with asc2mid, it just produces an empty file (0 bytes).

PHASE 2
I then tried it with my "prettified" code, and that also compiled and runs.
mid2asc converts "mary1.mid" to "mary2.txt". 

Using Beyond Compare, I compared this "mary2.txt" with 
the "mary2.txt" converted by JRace's mid2asc, 
and it appears their version has some extra line breaks, 
which must break the conversion back to MIDI. 

When I tried converting the 2nd "mary2.txt" back to MIDI with asc2mid,
it produces a MIDI file "mary3.mid" and this time it isn't empty. 
However, something is wonky, because the file is silent until about 16 seconds in.
Using mid2asc again, I converted that back to text "mary4.txt",
and using Beyond Compare, compared it to "mary2.txt"
and the first half of the file is very different.

I went back to the JRace version, and tried converting the text file "mary2.txt"
that my version made (that had no extra line breaks) to MIDI "mary3.mid",
which is no longer empty, but that file is also silent until 16 seconds in.
So the asc2mid in both our versions must have the same problem.

PHASE 3
I also started trying to convert both progams to QB64.

CODE AND RESULTS
I have attached all the code and test files and results in the following ZIP files. 

Code: (Select All)
FILE                                     CONTENTS
--------------------------------------   ---------------------------------------------------------
MIDI_TO_CSV_v1_JRACE.zip                 JRace's version and test files and results.
MIDI_TO_CSV_v2_MADSCIJR.zip              MadSciJr's prettified version and test files and results.
MIDI_TO_CSV_TO_QB64_v0-01_MADSCIJR.zip   MadSciJr's WIP conversion to QB64.

PS is it possible to insert tables in this forum editor?


Attached Files
.zip   MIDI_TO_CSV_v1_JRACE.zip (Size: 14.12 KB / Downloads: 38)
.zip   MIDI_TO_CSV_v2_MADSCIJR.zip (Size: 38.77 KB / Downloads: 36)
.zip   MIDI_TO_CSV_TO_QB64_v0-01_MADSCIJR.zip (Size: 29.05 KB / Downloads: 37)
Reply
#16
(08-26-2022, 02:00 AM)mnrvovrfc Wrote:
(08-26-2022, 01:48 AM)TempodiBasic Wrote: stuff
You need to use the "code" delimeters if you're going to post something very long and annoying like that.

You're right!
I apologize but I must become confident with new icons in forum's reply page!
I clicked on the third icon from left (insert a quote) by excluding Code button and PHP button.
And so that long boring post has born!
Now I try to put into a code window so I can have scroll bars and not kilometer post!
Reply
#17
(08-26-2022, 02:54 AM)bplus Wrote:
(08-26-2022, 01:48 AM)TempodiBasic Wrote:
(08-25-2022, 11:32 PM)madscijr Wrote: But beyond this MIDI to CSV project, you may have seen my many posts going on about this ridiculous pipe dream of getting the PC to read 2 or more USB mice as separate input devices, for local multiplayer Pong games I have dreamed of for a long time. Well, I found some code that supposedly does that, and it is also in C! I gather that this mouse stuff is much lower level operations, and needs to be in a language like C, so that piece of software will probably be a DLL that a QB64 program calls. So yet another reason I would like a C compiler! And there is at least one other project that similarly has me looking at C code (I don't recall what it was, but it's there!)

Really, I am not that excited about doing C. It's a necessary evil and I just want to get the dirty work done, so I can get back to writing QB64 code! 

Anyway I hope that explains where I'm coming from a little more. Thanks again for your reply!

Ok MadSciJr
reading your answer to my post this is the first attempt to translate 
mid2asc.c

I have read the instructions to use it here http://www.archduke.org/midi/instrux.html

I have used C, but I've not so practice with all its structures and ways to code... never used and seen Assert.h  https://en.wikipedia.org/wiki/Assert.h
and never seen this way to assign a value to a string variable 
  buf[p][0]="CDEFGAB"[(n+700000)%7];

it seems to me
buf(p,0) = "CDEFGAB " + ltrim$(str$(n+700000 mod 7))

I have tried to compile this C code with Gcc /G++ getting back only so much warning about dirty use/assign/modify of *char and *string not compatible with ISO C and using wstring/ Wchar_t*   https://en.wikipedia.org/wiki/C_string_handling


Starting from code you have posted mid2asc.c   I have put in QB64 comment by ' the code in BASIC in relation with code in C showed above.

Quote:stuff

Just a first step towards your goal...


"... very long and... " 

what?

Hi Bplus,
I have had a problem on formatting the previous post... I clicked on "Insert a Quote"  button  at the place of " Code"

Here above I have cancelled the long boring post and it stays the nucleum of my message...
in the C code of file Mid2Asc.C   I have written , IMHO, the sequential code in QB64 just under each C block of code.
So I have type " ' " as starting character and then the QB64 code to get the same result and operations made in C code.

first dubt is
1.
 never seen this way to assign a value to a string variable  in C
  buf[p][0]="CDEFGAB"[(n+700000)%7];

it seems to me
buf(p,0) = "CDEFGAB " + ltrim$(str$(n+700000 mod 7))

2.
trying to compile by using G++ or GCC compilers I got a set of Warnings about a deprecated way to use Strings and the suggestion to use Wstring based on Wchar_t  type of data.

Thanks for reading
Reply
#18
(08-26-2022, 08:24 PM)TempodiBasic Wrote:
(08-26-2022, 02:00 AM)mnrvovrfc Wrote:
(08-26-2022, 01:48 AM)TempodiBasic Wrote: stuff
You need to use the "code" delimeters if you're going to post something very long and annoying like that.

You're right!
I apologize but I must become confident with new icons in forum's reply page!
I clicked on the third icon from left (insert a quote) by excluding Code button and PHP button.
And so that long boring post has born!
Now I try to put into a code window so I can have scroll bars and not kilometer post!

No worries! 
I am also still learning about the new forums editor. 
I still can't see how to make a simple table! LoL
I checked the help page at 
https://qb64phoenix.com/forum/misc.php?a...help&hid=7
and no tables. 
?!?
Reply
#19
Now the post has been shortened using the right icon in the editor of reply to posting.
Thanks for feedbacks
Reply
#20
(08-26-2022, 08:36 PM)TempodiBasic Wrote:  never seen this way to assign a value to a string variable  in C
  buf[p][0]="CDEFGAB"[(n+700000)%7];
That is a syntax error in C, perhaps not in C++. I've seen stranger things happen with C++ code, perhaps square-bracket operators were overloaded? Otherwise the intention of the programmer looks like one of the letters is being extracted.

Just doing buf[p][0]="CDEFGAB"; might not be allowed in C, must allocate memory for pointer for string "array", then more memory for each member of the array and then use "strcpy()" or something like that from "string.h". This is just my near-fundamental knowledge of that programming language...
Reply




Users browsing this thread: 25 Guest(s)