Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Aaron's Sonar Mp3 Patch v5.64


  • Please log in to reply
32 replies to this topic
aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
Aaron's Sonar Mp3 Patch version 5.6.4.0
For Cakewalk Sonar Users
...powered by LAME v3.99.5
Posted Image
Would you like to export Mp3s of any bitrate directly from Sonar? Yes.
No more messing around with third-party software for Mp3 encoding!

This is a permanent Mp3 encoder for all versions of Cakewalk Sonar which adds all available Mp3 options (44 of them) to Sonar's "Export Audio" dialog.
All Mp3 options are available instantly for use when the User exports an audio project. It does not expire like the trial encoder Sonar is shipped with,
and it also lets the User add tags which will show up in exported Mp3 files... namely Artist Name, CD Title, and Year.
I'll be able to add more tags once Cakewalk fixes a bug in Sonar which severely limits the amount of data that can be sent to the encoder.

The patch may be run at any time to change the information in the tags.
It automatically detects if your system is 32 or 64-bit and creates either a 32 or 64-bit mp3 encoder (matching User's system) the first time the script is run.
The encoder engines I use are Lame 3.99.b0, 32 and 64-bit. I included them into the script with rseding91's "Include virtually any file" function.
I've also received a ton of help from lots of people here which I appreciate very much. :)

Download latest version:
Aaron's Sonar Mp3 Patch Installer.exe (recommended, but uninstall any previous version first)
Aaron's Sonar Mp3 Patch.ahk
The "misc" folder (unpack into script dir)

Non-EXE users, please create this directory as your script dir:
*Your 32-bit Program Files folder*\Aaron's Sonar Mp3 Patch
...and place everything in it.

It is easiest to use the installer. Then all associated files the script makes are cleanly removed if/when you uninstall the program.

Version History:
2006:
v1.0.0.0 - built registry entry files with multiple Mp3 export options
v2.0.0.0 - built installer and shortcuts for registry entry files
v3.0.0.0 - built beta cmd GUI, updated encoder to 3.98.4, added more export options
v4.1.0.0 - new AutoHotkey GUI, edit boxes for Artist Name, CD Title and Year tags
v5.0.0.0 - added all Variable Bitrate and all Constant Bitrate export options
v5.1.0.0 - fixed User Account Control (UAC) issues for some x64 users
v5.2.0.0 - quotation marks are now allowed in Artist Name and CD Title tags
v5.2.2.0 - more information added to Uninstall entry in Programs and Features
v5.2.3.0 - improved forward-compatibility for detecting if system is 32 or 64-bit
v5.2.4.0 - only one 32 or 64-bit encoder is now compiled, instead of both
v5.2.5.0 - right-click "Email" function added, and another quotation mark issue solved
v5.3.0.0 - encoder is now created and located with improved alternate method
v5.3.1.0 - %A_UserName% variable is now used to display User's name on GUI
v5.3.2.0 - rebuilt and customized context menu to match GUI and display User's name
v5.3.3.0 - added info box to appear once for unknown systems, updated "Email" function
v5.3.4.0 - added custom graphics to GUI, and "Create Portable Version" function
v5.3.5.0 - detects if User has Sonar installed and shows message if it is not
v5.3.6.0 - saves tag info and displays that info each time patch is opened
v5.3.7.0 - program and message windows fade in when opened, and fade out when closed
v5.3.8.0 - saved tag information is now archived in User's Documents folder
v5.3.9.0 - solved issue with apostrophes in User Name causing patch to fail
v5.4.0.0 - double-clicking in edit box erases text, "No Sonar Software" message improved
v5.4.1.0 - moved most filepaths into variables to shorten the amount of code required
v5.4.2.0 - replaced flickery ToolTip hover function, the new one is very smooth
v5.4.3.0 - optimized some functions, replaced edit box tag detection with ternary code
v5.4.4.0 - other various code fixes and improvements, very many thanks to nimda
v5.4.5.0 - improved quotation mark handling and replaced some deprecated commands
v5.4.6.0 - updated encoders to v3.99.b0 for Sonar's default export bit depth of 32
v5.4.7.0 - mouse cursor now changes to hand when hovering over any of the buttons
v5.4.8.0 - built a better and smaller portable version and improved its functions
v5.4.9.0 - updated Path registry keys to contain double backslashes instead of singles
v5.5.0.0 - edit boxes revert back to default text if left empty and mouse focus moved
v5.5.1.0 - one-time message is now shown reminding User that this software is always free
v5.5.2.0 - removed Portable Version because it takes up too much space, which is ironic
v5.5.3.0 - added right-click "View Registry Entries", sends the info to a text file
v5.5.4.0 - optimized above function, User now has choice to view entries with Regedit
v5.5.5.0 - main window becomes partially transparent when message windows are active
v5.5.6.0 - added icons for each item in context menu, taken from Shell32.dll
v5.5.7.0 - upgraded rseding91's 'Store Any File' function to v2.2 as it is much faster
v5.5.8.0 - upgraded both encoder engines to v3.99b1 and included them in the program
v5.5.9.0 - removed all instances of "Gui, -/+Default" for compatibility and readability
v5.6.0.0 - upgraded both encoder engines to v3.99.2 and included them in the program
v5.6.1.0 - upgraded both encoder engines to v3.99-20111018 to obtain IDv3 tag update
v5.6.2.0 - added right-click "Check for Updates" and "Visit Website" menu entries
November 2011:
v5.6.3.0 - upgraded both encoder engines to v3.99.2 and included them in the program
March 2012:
v5.6.4.0 - upgraded both encoder engines to v3.99.5 and added PayPal "donate" button
v5.6.5.0 - corrected a crash if the update function cannot contact the download page


future plans:
- make all these tags editable and usable: "Comment, Artist, Album Artist, CD Title, Year,
Genre, Publisher, Encoded By, Copyright, Composer, Conductor, Band Description
"
(once Sonar's CommandLine bug is repaired)


I hope you Sonar fans appreciate this one :) Thank you all for your support and guidance.
Aaron Bewza

NOTE: This script makes a registry key named
"HKEY_CLASSES_ROOT\CakewalkExtAudioEncoders" with 44 subkeys in it.
It also makes a folder named either
"32-bit" or "64-bit" in the location
"%A_ProgramFiles%\Aaron's Sonar Mp3 Patch".
And a folder in Documents called
"%A_UserName%'s Sonar Mp3 Patch Logs"
It also adds a few bits of info to Add/Remove Programs with the addition of registry keys to
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Aaron's Sonar Mp3 Patch"

The EXE's uninstaller takes care of removing them, or they must be manually removed if you are using only the AHK script.

June 20th 2011: I've run into a small Sonar issue: If you are exporting separate tracks, the maximum limit is 256 at a time. I thought this was a bug with Sonar at first, but it is not... they've built it that way.
So if you want to export more than 256 tracks at a time, do 256 and then do the rest.

Solved: I tried to post the code here, but it is over 1200 lines and I kept getting errors trying to do it. I didn't know I could upload instead of post.

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
You could post it on autohotkey.net for free... :p

aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
yes! it seems the actual script is displayed properly from the second link. I didn't know that would happen. You really have some comments about this one nimda? I'm absolutely all ears. I admire your skills and would appreciate any input you may have :)

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
Well, it is a very large script. For that, it will take a while to process, but I can give you bits right now:

[*:6k3ce3xr]Instead of
Loop
{
   If A_Index > 100
      Break
}
Use Loop 100

[*:6k3ce3xr]I always prefer "var = value" to the outdated SetEnv

[*:6k3ce3xr]You might have a look at [VxE]'s ternary guide; I find ternary can often be more readable than 4-line if/else pairs

[*:6k3ce3xr]I suggest you put other's code off in functions near the bottom; f.ex it is not necessary to read the code for detecting 32/64 bit while following the script, but only to know that is what is happening. Therefore, you could wrap that code up in a function and use "OSType := Get32or64()" or similar. Needing to read through the tedious calls used in that merely breaks the flow of the script.
That is only one example; I do believe I recognized code from several topics which would be better off wrapped and tossed to the bottom.More constructive criticism and/or praise to come ;)

Edit:
[*:6k3ce3xr]HKCR is the key used for file extensions, which you seem to not be dealing with. Please relocate to HKCU

[*:6k3ce3xr]Also, DYK that the contents of continuation sections can be indented by using the LTrim option?

[*:6k3ce3xr]You might look into Gui +Label as you have at least 7 of them.

[*:6k3ce3xr]My general rule of thumb is that if the sae string appears > 3 times in a script, it should be in a variable. *looks at filepaths in script* ;)
I would prefer you to use %A_ScriptDir% instead of %A_ProgramFiles%\Aaron's sonar patch

[*:6k3ce3xr]Instead of sending TAB 4 to focus a control, use controlfocus.Edit2 and Edit3:
changed to list format.
[*:6k3ce3xr]Consider using RegExReplace instead of 6 lines of StringReplace, I can help you there, as can several others.
[*:6k3ce3xr]Instead of having one subroutine which sets global variable s for the tooltips, include them in the function like so:
Func(){
   ; variables for tooltips
   Static TT_1 := "trololol"
   ; tooltipping goes here
}
Thanks for commenting the script ;)

Edit4:
Bolded edits.
[*:6k3ce3xr]You don't need to escape quotes inside a traditional continuation section
(
You don't have an email program!
    
`"AaronBewzaMusic@hotmail.com`"

has been copied to your clipboard.
Right-click "Paste" it anywhere.
        )
You seem to have both escaped and unescaped quotes there^^

[*:6k3ce3xr]In fact, you don't need to escape colons either:
MsgBox, 4,,
    (
Are you sure you want to copy
the encoder to the location[color=red]:[/color]

%PortableFolder%?
    )

[*:6k3ce3xr]you have a 'return' outside of a function (look at the bottom of the script)
This is harmless, yet useless.

aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
you rock nimda! you are correct, even I am having trouble now keeping track of the various subroutines and sections. I see what people mean when they say they like readable code. That is (hesitantly) next on the list to do, cleaning this silly thing up and making it more presentable.
Although, I tried moving the section "Checks for tags from misc\tags.txt...." down to the bottom and making it a subroutine, but that mangled the edit boxes completely... at that point they would not show on XP unless i used TAB to cycle through them or if I actually clicked on them. weird.
:) I'm excited to hear what you have to say!
I am going to investigate the Ternary Guide... if I'm not mistaken, that allows things like delimiters (...|...|...|...) which I remember from earlier.

Loop 100
  GuiControl,,Progress, %A_Index%
  Sleep 1
seems to make the progress bar disappear.

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
You are mistaken :p
Made edit numero 1 , going back for more :)

stay tuned.

aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
awww I have to run away for a few hours, wifey is home soon and we are going to watch a movie. Believe me though, I'll be back to read your words of wisdom. Don't pull any punches because you might hurt my feelings... I can take it lol especially if it improves this particular script. I think I was grumpy earlier from not having a smoke.
I've gotten rid of the legacy SetEnv lines.

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
Made edit numero 2.

Your loop doesn't work because (drumroll...)
you forgot the block.
Loop 100
{
   ; Progress stuff
   ; You realise "Sleep 1" generally sleeps about 15ms?
}


aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
Loop 100 ; Controls how the progress bar operates
    {
      GuiControl,,Progress, %A_Index%
      Sleep 1 ; Sets progress bar updates to approximately 15 milliseconds
    }
Works perfectly! Thank you, I'll be back in a while :D

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
Bamp. You have a lot of reading to do ;)
But really, great script.

aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
Updated to version 5.40 (links in post #1 above)

ARGH! I did not see Nimda's recent edits above... so I've bumped this thread WAY too early.
It looks like I have more suggestions to read through! thank you Nimda... that looks like valuable stuff, I'm on it right away :D ...I've been gone a few days.
I took that advice and tried to clean the script up the best I could. I replaced a few legacy commands, moved some subroutines to the bottom area etc... I also added a function to clear the edit box when the User double-clicks in it with the left mouse button. I'm understanding function calls more clearly now :) reading is good stuff.
I looked into using Ternary to compact repetitive IfInString commands, and that is a novel idea to wrap them like that but I think I prefer the readability of the original default method.
I stumbled onto a fascinating bit of info (fascinating for me anyway)... having to do with sequential patterns using Loop. I'd like to perhaps name all the created registry keys using a Loop function, from 1 to 44. When I understand more about this I will try to integrate it.

EDIT:
HKEY_CLASSES_ROOT is where Sonar places a folder for external Mp3 encoders to hook up with Sonar, so it needs to be at that exact location... all of Sonar's patching in with other software is done here (I think).
I removed some unnecessary escapes, and looked at the bottom "Return". Does a script automatically "return" when it reaches the bottom? I think it adds a sense of ending to it, even though it may be useless.
"Gui 2:+LabelMyGui" seems an awesome way to shorten some attributes of multiple GUIs. It seems quite similar to CSS in a web page.

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
I hope I'm not sounding critical. A script of that size is a definite achievement. I'm just trying to help you learn and improve :)

Once you get through the above list, come over to this post ;)
I'm going to number these so you can comment on them by number

1.) I don't understand your use of continuation sections. You do stuff like
FileAppend,
(
 Some line %A_HH%`nAnother line
), foo.txt
Which is better written as either
FileAppend, Some line %A_HH%`nAnother line, foo.txt
or as
FileAppend,
(
Some line %A_HH%
Another line
), foo.txt

1.a)I'd like to stress you can indent the contents of a continuation section with the LTrim option.

2.)I'd also like to stress you move out of needing the script in A_ProgramFiles and instead using A_ScriptDir

3.) You don't need to check with IfInString before using StringReplace; StringReplace will simply have no effect if the string to find isn't in the haystack.

aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
Updated to version 5.41 in top post :)
Ok I've got this mostly together then. Thank you for your guidance for sure! You don't sound critical at all, only very helpful. I'll go point-by-point on what I have so far (epic failures in red, successes in green)...

--- wrapping up the stuff that detects 32 or 64-bit system into a function sounds great but I'm not understanding how to make it work correctly. If I bundle this one to the bottom of the script, "CD Title" and "Year" edit boxes do not show up at all on XP until mouse is positioned over them.

--- HKCR is necessary, I did not change it to HKCU. Sonar hooks up to external software at this location

--- I figured out LTrim! awesome stuff.


--- Gui +Label confused the #@$ out of me and I made a huge mess LOL so I dropped that for now

--- changed most filepaths to variables (great idea!)

--- instead of using %A_ScriptDir%, I used %A_WorkingDir% because for now, the "portable version" of this thing is only a copy of itself, and if it is run from somewhere else, it will create the "32or64-bit\Lame.exe" file in an incorrect location, and Sonar will throw an error when it tries to find it. I will change this once I include an actual portable version which gets written to the proper location.

--- ControlFocus did not want to happen for me. I used "GuiControl, Focus, Artist"


--- RegExReplace sounds wonderful, I'm still trying to understand the documentation for it. It actually seems to take up more space than StringReplace, and I keep getting Illegal Character errors:
Artist := RegExReplace("Artist", "Artist Name") ; Removes the default "Artist Name" text in Artist input box
  Artist := RegExReplace("Artist", "`,", "`;") ; Replaces commas with proper separators for multiple Artist Names
  Artist := RegExReplace("Artist", "`"", "`\`"") ; Escapes quotation marks with backslash for Commandline registry subkey
; ----This next section is temporary until Sonar can handle more text in CommandLine subkey------------------->>
  Artist := RegExReplace("Artist", "`\`"`\`"`\`"", "`\`"") ; Replaces triple quotations with singles--------------
  Artist := RegExReplace("Artist", "`\`"`\`"", "`\`"") ; Replaces double quotations with singles-----------------
  Artist := RegExReplace("Artist", "`\`"`\`"", "`\`"") ; Replaces any resulting double quotations with singles---
; ------------------------------------------------------------------------------------------------------------<<
  Album := RegExReplace("Album", "CD Title") ; Removes the default "CD Title" text in Album input box
  Album := RegExReplace("Album", "`"", "`\`"") ; Escapes quotation marks with backslash for Commandline registry subkey
; ----This next section is temporary until Sonar can handle more text in CommandLine subkey------------------->>
  Album := RegExReplace("Album", "`\`"`\`"`\`"", "`\`"") ; Replaces triple quotations with singles--------------
  Album := RegExReplace("Album", "`\`"`\`"", "`\`"") ; Replaces double quotations with singles-----------------
  Album := RegExReplace("Album", "`\`"`\`"", "`\`"") ; Replaces any resulting double quotations with singles---
I've tried with and without quotes, with and without escapes, no success at all ^^^ I wonder if I'm doing it right, can one line of RegExReplace take care of all the above? I tried /Q...../E as well with no change. Removing all the quotation marks from those strings (except the first and last ones) and adding backslash escapes to the remaining quotation marks is what I'm trying to do.

--- Including variables inside the tooltip functions (instead of setting global variables) sounds great as well... I'm still trying to understand how it works.


--- removed unnecessary escapes from everywhere (I think)

--- removed line breaks (`n) in some continuation sections, but I left a few because some of the blank empty lines in the script bugged me a little

--- removed all the IfInString code that did not need to be there
[/b]

I'll be working on the stuff posted in red. This is awesome, I'm learning more and more.

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010

I've tried with and without quotes, with and without escapes, no success at all

http://www.autohotkey.com/docs/Functions.htm
Read that page. I don't see how you managed a 1000 line script without knowing how to call functions :?

[*:9vjwp4k3]To replace triple, double, fourple quotes with singles, do this:
var =
(
"""triples"""
""""fourples""""
""doubles""
"singles"
"""""even fives?"""""
"They all go down to singles"
)
While InStr(var, """""")
   StringReplace, var, var,"",",All

MsgBox % var
This is very reliable, instead of your long line of stringreplaces.

[*:9vjwp4k3]Gui, Default

[*:9vjwp4k3]Turns out, you don't need %A_WorkingDir%\file.ext , because A_WorkingDir is where the script works. Instead, file.ext will do fine.

[*:9vjwp4k3]

StringReplace, cntrl, cntrl, %A_Space%,, All ; Removes spaces
      StringReplace, cntrl, cntrl, -,, All ; Removes dashes
      StringReplace, cntrl, cntrl, :,, All ; Removes semicolons
      StringReplace, cntrl, cntrl, \,, All ; Removes backslashes
      StringReplace, cntrl, cntrl, .,, All ; Removes periods
      StringReplace, cntrl, cntrl, `n,, All ; Removes line breaks

is the same as (var is for demo)

var = dash-dash;;semicolon \\back slash FTWperiod..`n`nline breaks and spaces
While RegExMatch(var, "[-;\\. `n]")
   var := RegExReplace(var, "[-;\\. `n]")
MsgBox % var
[*:9vjwp4k3]

If Artist = ; If nothing is present on line 6, or if misc\tags.txt does not exist...
      Gui, Add, Edit, x52 y100 w120 h20 +Left vArtist +Limit30, Artist Name ; "Artist Name" is used as default text, becomes Artist variable, up to 30 characters
    Else
      Gui, Add, Edit, x52 y100 w120 h20 +Left vArtist +Limit30, %Artist% ; Otherwise, text on line 6 is displayed

Can be made shorter with ternary at your discretion:
Gui, Add, Edit, x52 y100 w120 h20 +Left vArtist +Limit30, % Artist ? Artist : "Artist Name"
[*:9vjwp4k3]You still require the script to be in A_ProgramFiles. Please, please use SetWorkingDir, %A_ScriptDir% instead!

aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
Updated to version 5.42 in top post.

I'm very happy you've taken an interest in this script, Nimda. I was successful on 4 of the 6 points you made last post!
I have figured out that functions are just like subroutines, there is nothing complicated about making one. I also got the smooth tooltip hover text working, it is not flickery at all, it is very smooth.

1: This totally worked awesome for getting rid of extra quotation marks
While InStr(var, """""")
    StringReplace, var, var,"",",All
2: Custom GUI labels and window number assignments are melting my brain lol for the amount of code it would save

3: Good point about not needing %A_WorkingDir%\file.ext, most of them weren't needed. File.ext is fine because it follows the path from %A_WorkingDir%. Some stuff I had to leave alone with %A_ProgramFiles% in the path, like the Create Encoder function

4: I now understand RegExReplace more clearly:
While RegExMatch(var, "[-;\\. `n]")
   var := RegExReplace(var, "[-;\\. `n]")
does the trick!

5: Ternary messes up and throws errors on the following:
If Artist =
      Gui, Add, Edit, x52 y100 w120 h20 +Left vArtist +Limit30, Artist Name
    Else
      Gui, Add, Edit, x52 y100 w120 h20 +Left vArtist +Limit30, %Artist%
if displayed like this:
Gui, Add, Edit, x52 y100 w120 h20 +Left vArtist +Limit30, % Artist ? Artist : "Artist Name"
I think I'll leave it as is, for now. It looks like something to do with using variable names more than once.

6: Yes, the script is installed and needed in A_ProgramFiles, but the "create portable version" function makes a copy of the script wherever the User chooses. The "write encoder" function has to write to A_ProgramFiles in order for Sonar to locate it when it is used... it needs to be in that location. Until I build a small portable version to include, I can't use SetWorkingDir at %A_ScriptDir% yet... or it will create encoders all over the place which Sonar cannot find.
I fully understand what you mean, though :) WorkingDir will change to %A_ScriptDir% soon.


I hope I'm somewhat meeting your expectations... I love this stuff, it is very rewarding.