Text Chords to Beat Number

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
MusoCity
Posts: 95
Joined: 24 Mar 2018, 20:45

Text Chords to Beat Number

Post by MusoCity » 18 Jan 2022, 02:00

I want to read a text file that has the chord positions for a song.
I need the Part, the beat number that the chord occurs on and how many beats long, so in the Chord section below the first A occurs on beat 13 for 8 beats in an A Part.
User will set time signature:
bar_beats = 4 ; this is 4/4 time signature
bar_beats = 3 ; this is 3/4 time signature

[Chords] script reads here [ChordsEnd]
|a) = A part
|b) = B part
|end) = End part
|%| same chord no change for bar
|D| = D chord on beat 1 of the 4 beat bar
|/ CMaj7 / /| = CMaj7 on 2nd beat of the 4 beat bar
|/ / C /| = C on 3rd beat of the 4 beat bar
|/ / / C| = C on 4th beat of the 4 beat bar
if bar_beats = 3
| / G /| = G chord on beat 2 of the 3 beat bar

Text file:
[Chords]
|a) D| Gbm7| / / G /| A|%| Gbm| G| A|
|b) Bm| Gbm| G| / D / /| Bm| Gbm| G| A|
|a) D| Gbm| G| A| D| Gbm| G| A|
|b) Bm| Gbm| G| D| Bm| E| G| G A|end) D|
[ChordsEnd]
Last edited by MusoCity on 19 Jan 2022, 06:07, edited 1 time in total.

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Text Chords to Beat Number

Post by BoBo » 18 Jan 2022, 16:44

Assuming that you'll use | as the standard delimiter...
To get the 'part)'-part you could use InStr/SubStr/RegExMatch/StrSplit/...
InStr can deliver the occurrences of beats/chord per 'cell' as well.

Good luck 8-)

MusoCity
Posts: 95
Joined: 24 Mar 2018, 20:45

Re: Text Chords to Beat Number

Post by MusoCity » 18 Jan 2022, 23:57

If possible a bit of code would help get me started as I'm used to reading csv lines in Lua, thanks.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Text Chords to Beat Number

Post by swagfag » 19 Jan 2022, 00:01

what is this?
image.png
image.png (6.52 KiB) Viewed 1158 times

MusoCity
Posts: 95
Joined: 24 Mar 2018, 20:45

Re: Text Chords to Beat Number

Post by MusoCity » 19 Jan 2022, 04:58

| G A| = G on beat 1 and A on beat 3
| / G / A| = G on beat 2 and A on beat 4

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Text Chords to Beat Number

Post by BoBo » 19 Jan 2022, 05:14

How should the output be used? Written back into a file, further processing, ... :arrow: should [Chrords] ... [/Chords] be preserved in the output?

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Text Chords to Beat Number

Post by swagfag » 19 Jan 2022, 05:21

this makes no sense. assuming 4/4:
  • if | G A| is |G(hit), G(sustain), A(hit), A(sustain)|
  • if | /G/A| is |rest, G(hit), rest, A(hit)|
what is | /G A|?
  • |rest, G(hit), G(sustain), A(hit)|? or
  • |rest, G(hit), A(hit), A(sustain)|?
ur input is ambiguous

MusoCity
Posts: 95
Joined: 24 Mar 2018, 20:45

Re: Text Chords to Beat Number

Post by MusoCity » 19 Jan 2022, 05:50

BoBo wrote:
19 Jan 2022, 05:14
How should the output be used? Written back into a file, further processing, ... :arrow: should [Chrords] ... [/Chords] be preserved in the output?
I think write it to a table and a text file I think would be best, leave the chord tags out.

MusoCity
Posts: 95
Joined: 24 Mar 2018, 20:45

Re: Text Chords to Beat Number

Post by MusoCity » 19 Jan 2022, 06:18

swagfag wrote:
19 Jan 2022, 05:21
this makes no sense. assuming 4/4:
  • if | G A| is |G(hit), G(sustain), A(hit), A(sustain)|
  • if | /G/A| is |rest, G(hit), rest, A(hit)|
what is | /G A|?
  • |rest, G(hit), G(sustain), A(hit)|? or
  • |rest, G(hit), A(hit), A(sustain)|?
ur input is ambiguous
if bar_beats = 3 then
| / G A| = G on beat 2 and A on beat 3

if bar_beats = 4 then
| / G A /| = G on beat 2 and A on beat 3
| / G / A| = G on beat 2 and A on beat 4

All the forward slashes should have spaces, if no space G/C that will be a slash chord G with a C root.
This is direct copy set at bar_beats = 4
[Chords]
| Bm| E| G/C| G A|
[ChordsEnd]
[Chords]
| Bm| E| / G / A| G A|
[ChordsEnd]

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Text Chords to Beat Number

Post by swagfag » 19 Jan 2022, 07:35

im saying, if bar_beats = 4 and
| G A| is, according to ur previous post, supposed to be:
image.png
image.png (8.05 KiB) Viewed 1087 times
what the would something like | / G A| be?

would it be:
image.png
image.png (8.13 KiB) Viewed 1087 times
or would it be:
image.png
image.png (8.62 KiB) Viewed 1087 times
ie the input is ambiguous

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Text Chords to Beat Number

Post by BoBo » 19 Jan 2022, 07:53

Just out of curiosity, what's the name of the application that outputs that [Chords]-files?

MusoCity
Posts: 95
Joined: 24 Mar 2018, 20:45

Re: Text Chords to Beat Number

Post by MusoCity » 19 Jan 2022, 11:27

Band In A Box
The Lua script I made read the project file, I just thought this would be easier than doing this in AHK.

Code: Select all

    f = assert(io.open(filetxt, "rb"))
    
    local first_byte_sig = f:read(1)
    local name_bytes = f:read(1)
    --print("First byte = "..tostring(first_byte_sig))
    name_len = string.byte(name_bytes)
    --print("Name_length =" ..name_len)
    local bytes = f:read(name_len)
    --print("Name: "..tostring(bytes))
    local meter_denominator = 4
    --print("Meter: "..tostring(4).."/"..tostring(meter_denominator))
    local byte1 = string.byte(f:read(1))
    local byte2 = string.byte(f:read(1))
    local byte3 = string.byte(f:read(1))
    local keyByte = string.byte(f:read(1)) --read 
    local tempoByte = string.byte(f:read(1)) --read tempo byte
    
    if keyByte <= 17 then
      key = rootNames[keyByte]
      isMinor = false 
    else key = rootNames[keyByte - 17]
      isMinor = true
    end
    if isMinor then
      --print("Key : " ..key.. "m")
    else --print("Key: " ..key)
    end   

Image

MusoCity
Posts: 95
Joined: 24 Mar 2018, 20:45

Re: Text Chords to Beat Number

Post by MusoCity » 19 Jan 2022, 11:41

swagfag wrote:
19 Jan 2022, 07:35
what the would something like | / G A| be?
I pasted that in 4/4 and it goes on beat 2 and 3:

Image

MusoCity
Posts: 95
Joined: 24 Mar 2018, 20:45

Re: Text Chords to Beat Number

Post by MusoCity » 21 Jan 2022, 07:44

If someone could point me to a simple csv reader script that will create a table and save to text, I will try and work it all out.

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Text Chords to Beat Number

Post by BoBo » 21 Jan 2022, 08:49

Someone has left the building, so have a look at this meanwhile: viewtopic.php?f=6&t=34853

MusoCity
Posts: 95
Joined: 24 Mar 2018, 20:45

Re: Text Chords to Beat Number

Post by MusoCity » 21 Jan 2022, 16:58

Thanks already got that, I just wanted a simple code that I can use in the script without having to include.

MusoCity
Posts: 95
Joined: 24 Mar 2018, 20:45

Re: Text Chords to Beat Number

Post by MusoCity » 21 Jan 2022, 23:52

chords.txt:
[Chords]
|a) D| Gbm7| / / G /| A|%| Gbm| G| A|
|b) Bm| Gbm| G| / D / /| Bm| Gbm| G| A|
|a) D| Gbm| G| A| D| Gbm| G| A|
|b) Bm| Gbm| G| D| Bm| E| G| G A|end) D|
[ChordsEnd]

I have this bit that will read the lines between the chord tags, I just need to read each line and insert the Chord Part Beat into the ChordTable

Code: Select all

Filename = C:\Temp\chords.txt
FileRead, String, %Filename% 

Loop,parse,String,`n
{
	If (A_LoopField ~= "Chords]")
	{
		LineNum1 := A_Index
		;break
	}
}
Loop,parse,String,`n
{
	If (A_LoopField ~= "ChordsEnd")
	{
		LineNum2 := A_Index
		;break
	}
}
MsgBox Start line %LineNum1% End line %LineNum2%
ChordTable := [] 
Loop
{
    if (A_Index > LineNum2 -1)
        break  ; Terminate the loop
    if (A_Index < LineNum1 +1)
        continue ; Skip the below and start a new iteration
	    FileReadLine, OutputVar, %Filename%, %A_Index%
		
		;Parse line and write to ChordTable Chord Part Beat
		
		ChordTable[A_Index] := OutputVar 
    MsgBox,  %A_Index% : %OutputVar% 
}

MsgBox, % ChordTable[3]


BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Text Chords to Beat Number

Post by BoBo » 03 Feb 2022, 19:07

@MusoCity - BC you've opened a follow-up thread to this one already (linked by @mikeyww above) this thread will get locked. Rgds,

Bo :)

Locked

Return to “Ask for Help (v1)”