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
nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010

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.

Try
Gui, Add, Dedit, x52 y100 w120 h20 +Left vArtist +Limit30, % Artist = "" ? "Artist Name" : Artist


aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
...updated to version 5.43 :) (links in first post updated)

This ternary now works, and very well! I figured out the trick to the system-reported year line (removing the percent signs did it) :
Gui, Add, Edit, x52 y100 w120 h20 +Left vArtist +Limit30, % Artist = "" ? "Artist Name" : Artist
Gui, Add, Edit, x182 y100 w120 h20 +Left vAlbum +Limit30, % Album = "" ? "CD Title" : Album
Gui, Add, Edit, x312 y100 w50 h20 +Left vYr +Number +Limit4, % Yr = "" ? A_YYYY : Yr
This makes 12 lines of code into 3. Ternary is very impressive for short bursts of variables. I can see where it can get confusing for longer strings :)

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
WOW :!:
This script is getting both shorter and better at the same time!
Now, let's dig in a little. All the low hanging apples have been picked.
I will sit down and spend some serious time following the script, and give my advice.

The first piece is Gui, Default.
It shouldn't melt your brain at all!
Consider this:
Gui, 2: Add, Text,, hi
Gui, 2: Add, Button,, Bye
Gui, 2: Add, Edit, vEdit, Hello!
; ... MANY more lines all starting with Gui, 2:
; The above is the same as the below in functionality.
[color=red]Gui 2: Default[/color]
Gui, Add, Text,, hi
Gui, Add, Button,, Bye
Gui, Add, Edit, vEdit, Hello!
; ... MANY more lines, all MUCH more readable now that they are all just 'Gui'

________________________________________________________

The next item is organization. You are doing fairly well. However, I notice some inconsistencies. Inconsistencies are fine in small scripts. However, in a large script, they can be frustrating once a bug pops up.

Your number one inconsistency is functions vs subroutines. If you want to be a purist, Functions do not change state and return a value. Subroutines change state (e.g., modify variables/modify Gui, etc) and do not return a value. (In AutoHotkey, you can only pass parameters to functions, so we use them also when parameters need to be passed, instead of something like 'Param := false' then 'GoSub, some_sub_which_uses_Param_var')

So, you should (imo) do one of two things:
[*:sfkky45w]Do things the way described above, changing things like CheckCakeWalkKey() to GoSub CheckCakeWalkKey
[*:sfkky45w]Change everything to functions. (Not to subs; they can't receive params)
________________________________________________________

I lied! there is a low hanging apple!
Your ButtonInfo sub looks like
ButtonInfo: ; Creates button "Info" which opens misc\info.html instructions page
  SoundPlay, misc\shot.wav ; Plays this sound when Info button pressed
  FileAppend, %A_Hour%`:%A_Min% - Displayed Instructions`n, %LogFile% ; Writes entry to misc\uselog.txt file...
  IfExist, misc\info.html ; Looks for instructions file
    {
      Run misc\info.html ; Opens instructions file
      Return
    }
  IfNotExist, misc\info.html ; If file does not exist, message is displayed
    {
      MsgBox, File is not available`. ; Message displayed
      Return
    }
Return
But it could look like
ButtonInfo: ; Creates button "Info" which opens misc\info.html instructions page
  SoundPlay, misc\shot.wav ; Plays this sound when Info button pressed
  FileAppend, %A_Hour%`:%A_Min% - Displayed Instructions`n, %LogFile% ; Writes entry to misc\uselog.txt file...
  IfExist, misc\info.html ; Looks for instructions file
      Run misc\info.html ; Opens instructions file
  IfNotExist, misc\info.html ; If file does not exist, message is displayed
      MsgBox, File is not available`. ; Message displayed
Return
Or like
ButtonInfo: ; Creates button "Info" which opens misc\info.html instructions page
  SoundPlay, misc\shot.wav ; Plays this sound when Info button pressed
  FileAppend, %A_Hour%`:%A_Min% - Displayed Instructions`n, %LogFile% ; Writes entry to misc\uselog.txt file...
  IfExist, misc\info.html ; Looks for instructions file
    {
      Run misc\info.html ; Opens instructions file
      Return
    }
      MsgBox, File is not available`. ; Message displayed
Return
;)
This is because you are 'returning' whether or not it exists.
MenuViewVersionHistory is the same way.

Also, please consider using 'Else' instead of opposing If* commands, as it is more clear at a glance.

Also, the if* commands are deprecated, and will not be included in AHKv2.
Instead, I prefer to use If FileExist() instead of IfExist. This is up to you, but I strongly suggest a switch.

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

1. Gui, Default is now understood completely. I was over-complicating things as I expected numbering Gui's to be more difficult than it was. Thank you for the clear example, there was no clearness like that in the documentation :)

2. A Function, by its nature, returns a value (it does the "math") and a Subroutine, by its nature, changes stuff around (they don't do calculations or values). I see the purism that can be applied here, and I've changed two functions back into subroutines.

3. Low hanging apples have been picked off with a pellet gun! 40 lines of IfExist/IfNotExist have now become 16 lines instead


4. When you say that 'If*' commands are deprecated, does that mean statements like: "If bla bla bla" (with a space after the 'if') or ones like "IfExist bla bla" (without a space after the 'if')? In any case, I'm unable to determine which 'If' statements are the opposing ones and if they should be changed. There's the three 'If's in the section that determines if system is 32 or 64-bit but I don't see how those can be altered. I tried putting an "Else" on line 143 in place of "If (arc = 6)..." but it makes errors.

Very appreciative of the progress you've helped me achieve, nimda, I've given you credits for your help, in the version history, if that's ok with you.

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
EDIT: Low hanging apple spotted :D

StringReplace, Artist, Artist,"",[color=red]`"[/color],All

Should be
StringReplace, Artist, Artist,"",[color=red]"[/color],All
And the like. Never escape quotes with a `
The only time you should ever escape quotes is in an expression, and there you do it by doubling the quote.
You have many lines like this; try ctrl+f and search for `"
_________________________________________________________

When you say that 'If*' commands are deprecated, does that mean statements like: "If bla bla bla" (with a space after the 'if') or ones like "IfExist bla bla" (without a space after the 'if')? In any case, I'm unable to determine which 'If' statements are the opposing ones and if they should be changed. There's the three 'If's in the section that determines if system is 32 or 64-bit but I don't see how those can be altered. I tried putting an "Else" on line 143 in place of "If (arc = 6)..." but it makes errors.

Very appreciative of the progress you've helped me achieve, nimda, I've given you credits for your help, in the version history, if that's ok with you.

Number two first: I'm fine with credits :D
Now, the If* commands. These are things like IfExist, IfWinActive, etc. They are deprecated, and can easily be switched for If FileExist() and If WinActive().
The second, function method is preferred, and will be your only option in the distant future...

About opposing commands: I mean things like
IfExist file
 ; ...
IfNotExist file
 ; ...
Statements like these should be changed to:
If [color=red]FileExist("File")[/color]
 ; ...
[color=red]Else[/color] ; The file doesn't exist
 ;...
Opposing If's are generally any two statements which are logically not equivalent, like If x=1 and If x=2.
While they seem innocent, they can cause nasty errors:
; Example code to show errors in opposing if's
x = 1

h::
 If x = 1
  x=2
 If x = 2
  x=1
 Send %x%
return
; The error here is that although it seems logical, '2' will NEVER be sent.
; Instead, use this:
I::
 If x=1
  x=2
 Else If x=2
  x = 1
 send %x%
return

;OR, in some cases this is better:
j::
 If x=1
  x=2
 Else
  x=1
 Send %x%
return

; This can be ternaried:
k::Send % x=2 ? x := 1 : x := 2
_____________________________________________________

EDIT2: Here is a perfect example of where a function could be used:
RemoveDupeQuotes(string){ ; By nimda - may be used freely
  While InStr(String, """""") ; Looks for multiple quotation marks in variable
    StringReplace, string, string,"",",All
  return string
}
Which can then be used in your code like:
Artist := RemoveDupeQuotes(Artist), Album := RemoveDupeQuotes(Album), thirdVar := RemoveDupeQuotes(thirdVar)


aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
Updated to version 5.45 (links in top post) :D
Lots of green text in this post!

1. Quotation marks - I assumed Scite was telling me the truth that there was bad code, when it outlined the non-escaped quotation mark in red as shown by this screenshot:
Posted Image
...yet it works correctly without escaping, like you said. All instances of escaped quotation marks are now non-escaped.

2.This works well:
If FileExist(LogFile) ; Looks for uselog.txt file
    Run %LogFile% ; Opens uselog.txt file
  Else ; If file does not exist, message is displayed
    MsgBox, File is not available. ; Message displayed

3. Your function works awesome! I added the line that puts backslashes on any remaining quotation marks to escape them for the CommandLine (on lines 169 and 171, function is on line 715)
Artist := RemoveDupeQuotes(Artist) ; Calls function to replace multiple quotation marks with singles in "Artist" variable
Album := RemoveDupeQuotes(Album) ; Calls function to replace multiple quotation marks with singles in "Album" variable

; ------------------------------------------------------------------------------------------------------------!!
; Function to remove duplicate quotation marks (by nimda)-----------------------------------------------------!!
; ------------------------------------------------------------------------------------------------------------!!
RemoveDupeQuotes(String) { ; Removes multiple quotation marks
  While InStr(String, """""") ; Looks for multiple quotation marks in variable
    StringReplace, String, String, "", ", All ; Replaces multiples with singles
    StringReplace, String, String, ", \", All ; Escapes quotation marks with backslashes to prevent errors in the created registry keys
  Return String ; Sends variable back without multiple quotation marks and escaped with backslashes
}
It sure tidies up that section of the script. Why didn't I think of this? :D

4. I figured out how to handle the remaining "IfNotExist" commands. I went from this:
IfNotExist, %A_ProgramFiles%\Aaron's Sonar Mp3 Patch\32-bit\lame.exe ; If this file does not exist, function is called to create it
    {
      FileCreateDir, %A_ProgramFiles%\Aaron's Sonar Mp3 Patch\32-bit ; Creates the folder for 32-bit encoder
      Write32enc_extract(A_ProgramFiles "\Aaron's Sonar Mp3 Patch\32-bit\lame.exe") ; Calls "Write32enc_extract" from bottom of script, creates encoder
    }
to this:
If FileExist(A_ProgramFiles "\Aaron's Sonar Mp3 Patch\32-bit\lame.exe") ; If this folder and file exist, no need to create it
    Return
  Else {
      FileCreateDir, %A_ProgramFiles%\Aaron's Sonar Mp3 Patch\32-bit ; Creates the folder for 32-bit encoder
      Write32enc_extract(A_ProgramFiles "\Aaron's Sonar Mp3 Patch\32-bit\lame.exe") ; Calls "Write32enc_extract" function, creates 32-bit encoder
    }
This appears to make an apple hang lower on the tree, but that is ok since now it is a very good quality apple and not about to go rotten anytime soon.

EDIT June 2nd: Very strange behavior with the ToolTip text on the Info and Exit buttons... the ToolTip will stop appearing after clicking a few buttons and opening a few menus. And it does not ever come back, until the script is reloaded. Then everything is fine again for a while but inevitably the problem returns. It is strange because no other controls lose their ToolTips at all, at any time. If I open the script from Scite or if I open the compiled EXE, the problem happens. The only time it does not happen is when the actual AHK script is run. Then I cannot reproduce it.
I thought it may be related to Gui Default, but I put this:
Gui, -Default
into the exit routine of all the secondary GUIs but there has been no change. I also tried moving the two "Gui, Button" lines higher up in the script to rule out that it was because they are the last two built, and are the last two worked on in the ToolTip function, but no change

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
@#4
If Not FileExist(File)
{
   ; Stuff
}
better apple :)

aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
...updated to version 5.46 (links in top post) with an upgrade of the encoder engines to version 3.99.b0

:oops: ohhhhh lol... thank you for that! It makes more sense. Now I've got this:
If Not FileExist(A_ProgramFiles "\Aaron's Sonar Mp3 Patch\32-bit\lame.exe") { ; If 32-bit encoder does not exist in this location, it is created
    FileCreateDir, %A_ProgramFiles%\Aaron's Sonar Mp3 Patch\32-bit ; Creates the folder for 32-bit encoder
    Write32enc_extract(A_ProgramFiles "\Aaron's Sonar Mp3 Patch\32-bit\lame.exe") ; Calls "Write32enc_extract" function, creates 32-bit encoder
  }

I think the ToolTip problem might be with the message GUIs being created and destroyed. I tested by replacing one with a plain MsgBox and it would not trigger the problem. I narrowed it down even further by removing the "fade" function from the message GUIs with no change. I also tried removing the Gui, Default commands in case switching default windows was causing it, but it wasn't.

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
Aha!
Until now, it has been fairly easy going.
Now, you have a bug. You are finding it hard to reproduce the bug.
In fact, you have no idea if it's a bug with AutoHotkey, someone's function, or your script.
This will truly be a challenge, and a learning experience.

You must look into your code from the outside, not saying "oh, this does that" but instead saying "I think this will do that by causing these actions."

If (when) that does not work, start putting breakpoints into your script. One way that a tooltip won't show up is
ToolTip %BlankVar%
... so you should be using listvars.

I hope you look on this as a challenge, and continue until you hit that 'DOH! That's why! (now, how do I fix it?)' stage.

GuitarMan
  • Members
  • 3 posts
  • Last active: Jun 06 2011 06:32 AM
  • Joined: 04 Jun 2011
Thanks for posting your program.

It doesn't seem to function with my Sonar 3.

There were no errors in your program, but within Sonar 3 there is no sign of new export options in the export menu.

aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
Which operating system are you on? Which edition of Sonar 3?
The new options are supposed to appear underneath the default options, here in the "Export Audio" dialog box:
Posted Image
I'm not sure why they are not showing up for you... but I've got Sonar 3 PE tucked away somewhere which I can install later today, and I will check it out. Did you try restarting Sonar and then checking for the new entries?

Cakewalk has used the "HKEY_CLASSES_ROOT\CakewalkExtAudioEncoders" location for these entries since the dawn of time, I'm very curious why it is not working for you.

So, let me know which OS you have and what edition Sonar (producer, home, etc), and what you've tried... hopefully I can figure this out for you :)
Aaron

EDIT: I have access to Sonar 4 Producer Edition, that's the oldest one I have. My buddy still has Sonar XL and reports no problems on XP. It may be something to do with not having an Administrator level account...?

aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
nimda... that is a great perspective, I approached the bug in that manner with positive results. I cannot trigger it at all now since I shuffled the order of these three lines (in all message GUIs) into this order:
Gui, 1: +Disabled ; Disables main window underneath

  Gui, 6: +owner1 ; Make the main window the owner of About message window

  Gui, 6: Default ; Makes this window the default
and it has not happened since.

GuitarMan
  • Members
  • 3 posts
  • Last active: Jun 06 2011 06:32 AM
  • Joined: 04 Jun 2011
I am Using Sonar Producer 3.0 with Windows XP pro. Yes I did restart Sonar. I also uninstalled and then re-installed the MP3 patch using your program. I also tried restarting the computer, re-running Sonar & saying a prayer. None of which solved the problem. Let me know if you need further info.

aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
...ok let's check the location the patch writes entries to.

- install patch, add all mp3 options
- open "regedit" (windows key + R, then type regedit in the box)
- open HKEY_CLASSES_ROOT and look for a key called "CakewalkExtAudioEncoders"... this is where the patch works with Sonar.
- click on it so it expands and shows the keys inside, and click on any one so its info shows up on the right.

If everything is ok so far, you should see these keys:
Posted Image
...and if those keys are there, Sonar should see them.

You could test if it's an issue with your Sonar if you use the "External Encoder Configuration Utility" located up in the menu:
- open the External Encoder Configuration Utility
- type Mp3 128 kbps (or whatever you want for a test) into the "friendly name" box
- type .mp3 in the "extension" box
- in the "path" box, type the full location of the encoder (C:\Program Files\Aaron's Sonar Mp3 Patch\32-bit\lame.exe usually, or use the "browse" button to find it).
- in the "commandline" box, type lame -b 128 -m a %I %O
- finally, click "save".

...try looking for that entry in the Export Audio box under file type. If it is not there, something is buggy with the way your Sonar configures an external encoder. If that's the case, I would suggest an upgrade to at least Sonar 6 for your XP, it's way more of a program but isn't a huge resource hog. :)

Your problem seems to be unique, but my curiosity is stoked and I'm wanting to know what's up with it too.

aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
Updated to version 5.47 (links in top post, click HERE to go to top post) :)
... Now the mouse cursor changes to a hand when hovering over any of the buttons. I managed to use part of this function: "Changing the Mouse Cursor" inside the same function as the ToolTip hover text I'm already using. Tested and working in XP, Vista, and 7 (32 and 64-bit)