#65541 - thegamefreak0134 - Tue Jan 03, 2006 10:15 pm
Hello! I have a small issue here. I have two functions used for converting a certain type of number in a MIDI file to a useable number in C++. (and vice versa, for saving. I was wondering if anyone would be able to convert these from C++ code to Visual Basic code, as I am much more fluent in that language and will be coding my program in it.
The reason is that I want my easy s3m editor to also be able to double as a MIDI to s3m and back converter, and do all the things I need it to. If someone can, let me know and I'll find and post the functions. (I would now, but I don't have them with me... sad.) Thanks in Advance. (or thanks in color, for you old schoolers.)
_________________
What if the hokey-pokey really is what it's all about?
[url=http:/www.darknovagames.com/index.php?action=recruit&clanid=1]Support Zeta on DarkNova![/url]
#65549 - ScottLininger - Tue Jan 03, 2006 10:47 pm
Post away...
-Scott
#65605 - NoMis - Wed Jan 04, 2006 9:42 am
Ahhh VB :(
What part of the conversion is troubling you exactly? Can you provide any sample code that you particulary have problems with?
Why are you not putting these C++ functions into a DLL? VB can use them with no problem.
Or is this not an option?
Are you using VB or VB.NET?
NoMis
_________________
www.gamedev.at - The austrian gamedev site
hde.gamedev.at - The Handheld Dev Env plugins for Eclipse
#65656 - thegamefreak0134 - Wed Jan 04, 2006 8:45 pm
Well... now I'm having issues... I can't seem to find the original functions. Stay tuned though, I should be able to find them sometime this week. I'll hand copy them from the printout if neccessary...
_________________
What if the hokey-pokey really is what it's all about?
[url=http:/www.darknovagames.com/index.php?action=recruit&clanid=1]Support Zeta on DarkNova![/url]
#66557 - thegamefreak0134 - Wed Jan 11, 2006 10:54 pm
yay! (The filter gave me issues again...) I found the functions. Here they are:
Function 1:
------
WriteVarLen (value)
register long value;
{
register long buffer;
buffer = value & 0x7f;
while ((value >>= 7) > 0)
{
buffer <<= 8;
buffer |= 0x80;
buffer += (value & 0x7f);
}
while (TRUE)
{
putc(buffer,outfile);
if (buffer & 0x80)
buffer >>= 8;
else
break;
}
}
Function 2
-------
doubleword ReadVarLen ()
{
register doubleword value;
register byte c;
if ((value = getc(infile)) & 0x80)
{
value &= 0x7f;
do
{
value = (value << 7) + ((c = getc(infile)) & 0x7f);
}
while (c & 0x80);
}
return (value):
}
End of functions.
These two functions deal with converting variable length 7-bit numbers to 8-bit numbers. One reads a 7-bit from a file and turns it into an 8-bit variable, and the other takes an 8-bit variable and writes a 7-bit variable length 7-bit number to a file. Both are important, and I would like a version of these for Visual Basic 6.0 if at all possible. Thanks a million if you can help!
_________________
What if the hokey-pokey really is what it's all about?
[url=http:/www.darknovagames.com/index.php?action=recruit&clanid=1]Support Zeta on DarkNova![/url]
#66572 - strager - Thu Jan 12, 2006 12:55 am
I think I have gotten the first function down. Here's the messy code. I can't guarentee that it will work, because my VB skills are... rusting (and they deserve to be!). I think that the "And" operator uses the bitwise routine like "&" does in C, but I'm not sure. This may be the reason the code fails, if it does.
Code: |
' WriteVarLen(register long value) {
Function WriteVarLen(Dim value As Long)
' register long buffer;
Dim buffer As Long
' buffer = value & 0x7F;
' I think!
buffer = value And (2 ^ 7 - 1)
' while((value >>= 7) > 0) {
While 1 Do
' I think!
If value / (2 ^ 7) == 0 Then
break
End If
' buffer <<= 8;
buffer = buffer * (2 ^ 8)
' buffer |= 0x80;
' I think!
buffer = buffer Or (2 ^ 8)
' buffer += (value & 7F)
' I think!
buffer = buffer + (value And (2 ^ 7 - 1))
' }
End While
' while(TRUE) {
While 1 Do
' Put your own write routine here
' I think!
PrintChar(myfile, buffer And (2 ^ 8 - 1))
' if(buffer & 0x80) {
' I think!
If buffer And (2 ^ 7) Then
' buffer >>= 8;
buffer = buffer / (2 ^ 8)
' } else {
Else
' break;
break
' }
End If
' }
End While
' }
End Function
|
You may need to fix a few things, like the while loop structure. I haven't come across using while loops in VB, ever, because I have no use for them in VB (in "login" screens with the worst security ever, I mean).
Happy coding,
strager
#66644 - thegamefreak0134 - Thu Jan 12, 2006 5:45 pm
OK. The write functions shouldn't be too hard to add myself. The way they work, you declare a file as open for binary access, and then read onb byte at a time, I believe. The routine simply states something to the effect of:
Variable = Write routine.
So what I need to know is what variable needs to contain the single byte I'm pulling from the file. Also, how would I use said function?
If possible, if someone could translate this into psuedo-code I might be able to make it work. It's mainly that I don't understand the byte level stuff the C++ program is doing, and even if I did I don't know how to do them in VB (or even if it's possible.) Thanks a million so far. I'll try to get this function working!
-gamefreak
PS: This is still coming through a filter. Wow...
_________________
What if the hokey-pokey really is what it's all about?
[url=http:/www.darknovagames.com/index.php?action=recruit&clanid=1]Support Zeta on DarkNova![/url]