Text Chords to Beat Number
Text Chords to Beat Number
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]
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.
Re: Text Chords to Beat Number
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
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
Re: Text Chords to Beat Number
If possible a bit of code would help get me started as I'm used to reading csv lines in Lua, thanks.
Re: Text Chords to Beat Number
| G A| = G on beat 1 and A on beat 3
| / G / A| = G on beat 2 and A on beat 4
| / G / A| = G on beat 2 and A on beat 4
Re: Text Chords to Beat Number
How should the output be used? Written back into a file, further processing, ... should [Chrords] ... [/Chords] be preserved in the output?
Re: Text Chords to Beat Number
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)|
- |rest, G(hit), G(sustain), A(hit)|? or
- |rest, G(hit), A(hit), A(sustain)|?
Re: Text Chords to Beat Number
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]
Re: Text Chords to Beat Number
im saying, if bar_beats = 4 and
| G A| is, according to ur previous post, supposed to be: what the would something like | / G A| be?
would it be: or would it be: ie the input is ambiguous
| G A| is, according to ur previous post, supposed to be: what the would something like | / G A| be?
would it be: or would it be: ie the input is ambiguous
Re: Text Chords to Beat Number
Just out of curiosity, what's the name of the application that outputs that [Chords]-files?
Re: Text Chords to Beat Number
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.
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
Re: Text Chords to Beat Number
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.
Re: Text Chords to Beat Number
Someone has left the building, so have a look at this meanwhile: viewtopic.php?f=6&t=34853
Re: Text Chords to Beat Number
Thanks already got that, I just wanted a simple code that I can use in the script without having to include.
Re: Text Chords to Beat Number
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
[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]
Re: Text Chords to Beat Number
@MusoCity - BC you've opened a follow-up thread to this one already (linked by @mikeyww above) this thread will get locked. Rgds,
Bo
Bo