Bach.roll: getting the index of the headers last element

Discussions, advice, bug reports and much more about the "bach" environment.
Post Reply
sydy
Posts: 156
Joined: Tue Mar 21, 2017 1:34 pm

Bach.roll: getting the index of the headers last element

Post by sydy » Mon Jun 13, 2022 7:34 am

How would you get the index of a dump bach.roll's body beginning if you don't want to dump the body but want to extract it from a whole dump?

My first intuitive answer was to search the last element of the header. As far as I understand this must be the loop information.

But I'm currently not sure if the header's last element is always the loop information. Could you confirm this or give me a better strategy?

Thanks

danieleghisi
Site Admin
Posts: 1349
Joined: Fri Dec 03, 2010 1:25 pm

Re: Bach.roll: getting the index of the headers last element

Post by danieleghisi » Mon Jun 13, 2022 9:50 am

Hello. If you just need to slice the header you can use bach.sliceheader

If you want to know how this works, the idea is that the header goes on as long as there are lists of the kind

[ somesymbol .... ] [ someothersymbol ... ] ...

The first sublist not starting with a symbol is the beginning of the body, namely the first voice.

Best
Daniele

sydy
Posts: 156
Joined: Tue Mar 21, 2017 1:34 pm

Re: Bach.roll: getting the index of the headers last element

Post by sydy » Tue Jun 14, 2022 10:46 pm

Great. That's the way I understood it.
So bach.sliceheader does under the hood something like:

## input is a full dump. We look for the body.
$input = $x1.right(1) ; ## take out router 'roll'
$inlen = $input.length() ; ## get length
$check = 0; ## init condition var

## loop through the dump
for $i $addr in 1 ... $inlen as $check < 1 do(
## check if the first entry is a symbol
if contains($input:$i:(1 1)) == 16 then $check = 0
else (
$check = 1 ;
$input:$i ## the current entry is the body
)
)

––––
I love contains()
Best,
Micha

Post Reply