Page 2 of 2
Re: RegExReplace Transpose Chords
Posted: 20 Jun 2018, 18:00
by MusoCity
Thanks ! very close to working right.
this works to allow for just one chord (without / slash note) or two (with or without / slash notes)
Code: Select all
q:: ;test transpose chords
vText := "Cm7b5#9/B"
MsgBox, % ChordTranspose(vText, 1)
MsgBox, % ChordTranspose(vText, 0, 1)
MsgBox, % ChordTranspose(vText, 0, 0, 1)
MsgBox, % ChordTranspose(vText, 0, 0, 0, 1)
MsgBox, % ChordTranspose(vText, -1)
MsgBox, % ChordTranspose(vText, 0, -1)
MsgBox, % ChordTranspose(vText, 0, 0, -1)
MsgBox, % ChordTranspose(vText, 0, 0, 0, -1)
return
But if it has the second chord only (,3) so it starts with "," it won't work
Code: Select all
q:: ;test transpose chords
vText := ",Cm7b5#9/B"
MsgBox, % ChordTranspose(vText, 1)
MsgBox, % ChordTranspose(vText, 0, 1)
MsgBox, % ChordTranspose(vText, 0, 0, 1)
MsgBox, % ChordTranspose(vText, 0, 0, 0, 1)
MsgBox, % ChordTranspose(vText, -1)
MsgBox, % ChordTranspose(vText, 0, -1)
MsgBox, % ChordTranspose(vText, 0, 0, -1)
MsgBox, % ChordTranspose(vText, 0, 0, 0, -1)
return
Re: RegExReplace Transpose Chords
Posted: 20 Jun 2018, 18:39
by jeeswg
- I've edited the original function (in a previous post) by adding these 2 lines:
- The reason I missed this relates to the fact that you can't do
!(vST is "number") in AHK v1 (yet?). I got distracted by this, so didn't handle the case where the number could be 0. I would normally put the 2 checks together on the same line.
- Here I've combined my and your examples into a continuation section, to show the results in one MsgBox instead of multiple MsgBoxes.
Code: Select all
q:: ;test transpose chords
vText := "A/B,C/D"
vText := ",Cm7b5#9/B"
vOutput := ;continuation section
(Join`s"`n"`s Comments
ChordTranspose(vText, 1)
ChordTranspose(vText, 0, 1)
ChordTranspose(vText, 0, 0, 1)
ChordTranspose(vText, 0, 0, 0, 1)
ChordTranspose(vText, -1)
ChordTranspose(vText, 0, -1)
ChordTranspose(vText, 0, 0, -1)
ChordTranspose(vText, 0, 0, 0, -1)
ChordTranspose(vText, 1, 1, 1, 1) ;A#/C,C#/D#
ChordTranspose(vText, 2, 2, 2, 2) ;B/C#,D/E
ChordTranspose(vText, -1, -1, -1, -1) ;G#/A#,B/C#
ChordTranspose(vText, -2, -2, -2, -2) ;G/A,A#/C
)
MsgBox, % vOutput
return
Re: RegExReplace Transpose Chords
Posted: 20 Jun 2018, 19:18
by MusoCity
Perfect ! I will put it in the code and try it out and let you know, thanks again !
Re: RegExReplace Transpose Chords
Posted: 21 Jun 2018, 02:22
by MusoCity
It's working good with the # sharp chords but not picking up the flat b chords Db Eb Gb Ab Bb
C Db D Eb E F Gb G Ab A Bb B
Re: RegExReplace Transpose Chords
Posted: 21 Jun 2018, 02:29
by jeeswg
- You can pass a note array as one of the parameters in the function.
Code: Select all
oArray := StrSplit("C,C#,D,D#,E,F,F#,G,G#,A,A#,B", ",")
oArray := StrSplit("C,Db,D,Eb,E,F,Gb,G,Ab,A,Bb,B", ",")
- I could improve the function to handle both types of notes as the *source* (needle) note, but the function has to be told what type of *destination* (replacement) note to use (# or b).
Re: RegExReplace Transpose Chords
Posted: 21 Jun 2018, 13:09
by MusoCity
I think the # should be default, I have another function to to convert #>b or b># anyway.
Re: RegExReplace Transpose Chords
Posted: 21 Jun 2018, 17:27
by jeeswg
- Interesting. Btw do # or b (case sensitive) ever appear in the text (chord) but not as part of notes.
- In the function definition, you can specify oArray2, to allow you to use the flats instead of the sharps:
Code: Select all
ChordTranspose(vText, vST1:="", vST2:="", vST3:="", vST4:="", oArray2:="")
- Are there any further complications that you envisage?
Re: RegExReplace Transpose Chords
Posted: 21 Jun 2018, 18:11
by MusoCity
The only other occurrence of a lowercase b that is not related to a chord is following a "." ".." "..." at the very end of the chord Db...b or Db.db or Db..dbgps or C/G...b the dot indicated .=rest ..=shot ...=held
it is just telling the app to only play the d=drums, b=bass, g=guitar, p=piano or s=strings or combination on that chord rather than the whole band.
EDIT: The only occurrences it needs to pick up of the b is in the same position as the # it now picks up, so it's not picking up the other flat notes in some chords eg. Dbm7b5#9 it will always be after A-G
Re: RegExReplace Transpose Chords
Posted: 24 Jun 2018, 02:59
by MusoCity
I got that working good now thanks !
After if found the Db I put a gosub ChordB/# to rename the Db to C# get it pass the check then put another gosub Chord#/b to rename it back to a flat then the Db is renamed to a D to go up 1 semitone.
You would probably have a one liner to do all that, but the main thing is it's all working !
Code: Select all
ChordTranspose(vText, vST1:="", vST2:="", vST3:="", vST4:="", oArray2:="")
{
static oArray := StrSplit("C,C#,D,D#,E,F,F#,G,G#,A,A#,B", ",")
static vNeedle1 := "^\^*\K"
static vNeedle2 := "^[^/,]*/\K"
static vNeedle3 := "^.*,\^*\K"
static vNeedle4 := "^.*,.*/\K"
static number := "number" ;AHK v1/v2 two-way compatibility
if IsObject(oArray2)
vArrayName := "oArray2"
else
vArrayName := "oArray"
Loop, 4
{
vST := vST%A_Index% ;semitone
if vST is not number
continue
if !vST
continue
if !vPos := RegExMatch(vText, vNeedle%A_Index% "[A-G]")
return
Global vNote1 := SubStr(vText, vPos, 2)
if FoundPos := RegExMatch(vNote1, "b")
b1=1
gosub Chordb/#
if !RegExMatch(vNote1, "[#b]$")
vNote1 := SubStr(vNote1, 1, 1)
for vKey, vValue in %vArrayName%
if (vValue = vNote1)
{
vNum1 := vKey
break
}
if !vNum1
return
vNum2 := 1+Mod(vNum1+11+vST%A_Index%, 12)
if (vNum2 <= 0)
vNum2 += 12
vNote2 := %vArrayName%[vNum2]
If b1=1
gosub Chord#/B
vText := RegExReplace(vText, vNeedle%A_Index% vNote1, vNote2)
}
return vText
}
return
Re: RegExReplace Transpose Chords
Posted: 24 Jun 2018, 11:24
by jeeswg
- It should be fairly easy to add the following to the script:
- If the input note contains # the output note will be one of: C,C#,D,D#,E,F,F#,G,G#,A,A#,B.
- If the input note contains b the output note will be one of: C,Db,D,Eb,E,F,Gb,G,Ab,A,Bb,B.
- The question is what to do if the input doesn't contain # or b, what then?
- My latest plan is to do the following, for the final parameter oArray2, if you specify "b" then b is used, if you specify "#" then # is used, if you specify "" then it uses 'smart' behaviour: # is used unless the input note contains b in which case b is used.
ChordTranspose(vText, vST1:="", vST2:="", vST3:="", vST4:="", oArray2:="")