#1 : 08/06-25 16:13 Sebastien Bernard
Posts: 2
|
Hello,
I'm a new user, I'm a musician, and I'd like to rename files in a particular way : I got several samples of instruments, note by note, sorted with numbers. I know they are from the lowest to the highest notes. Let's say I got 88 samples of a piano, each from one note, numbered from Piano1 to Piano88. But I'd like to rename them with the right name of the note, from Piano_A0 to Piano_C8. the 12 notes names are always the same, from A to G and a number after according to the octave. Is it possible to do it ? May be add a list of note names and increment them after a name ? Of course all the instruments don't have the same range, so I'd like to set a starting note for each one. Thanks in advance, I hope you'll have some solutions ! Runenlyd |
#2 : 09/06-25 09:52 Styb
Posts: 183
|
Reply to #1:
You need to create a text file containing the names of the white and black piano keys, with one name per line. For example: A0 A0# B0 C1 C1# D1 D1# E1 F1 F1# etc. etc. Import this text file using the 'List' method to rename the files. Next, use the 'Add' method to add 'Piano_' at the start of the name. I think this procedure is faster than manually renaming each file individually. |
#3 : 10/06-25 06:42 Sebastien Bernard
Posts: 2
|
Reply to #2:
Thanks for your answer Styb :) |
#4 : 16/06-25 04:49 Delta Foxtrot
Posts: 500
|
Reply to #3:
Hi guys, As an exercise I wrote a script that will take any instrument name, start (lowest) note, and start (lowest) octave number, and calculates the names of the notes. It may be too late, but Sebastien, if you are around and see this, I need some information to finalize the script: When the sharped notes are written (e.g. "F# in the 0 octave) are you looking to see it as "F#0" or "F0#"? And if the former, would you like some divider character to even out the length of the filename for sharped and natural notes? For example, "Piano_F#1" and "Piano_G_1" would be the same length (and therefore easier to read, in my opinion). But it's up to you; I don't know what you may be looking for. Do you want to start with the lowest octave on the piano being octave 0 or octave 1? The reason I ask is, in your piano example you started at "C0" but ended at "A8", and I think if you start as a base octave 0 the highest note would be "A7", wouldn't it? But if you start the lowest octave as "1" then the "A8" would be correct. I realize that you may already have converted all your samples, and this is all moot, but it might be of use to others in the future. I'm sorry I didn't get to it sooner but I was feeling a little un-script-y for a while. Being retired, and lazy, I don't always feel like jumping into projects right away. :) Right now I have the script start at octave 0 and add the octave after the full note name, i.e., Piano_A0 Piano_A#0 Piano_B0 Piano_C0 Piano_C#0 etc. It is trivial to change the base octave to 1; adding a spacing character would not be much more trouble. Changing the format to "F5#" rather than "F#5" would be a little tougher, but probably not too hard. Best, DF |
#5 : 17/06-25 05:31 Delta Foxtrot
Posts: 500
|
Reply to #4:
Well, I'm tired of thinking about this one, so here's the script the way I like it. Put the part that starts with PREBATCH, the top part, in the part marked Pre batch script... on the script method. The part marked MAIN goes in the main window (duh)... Before you run it you need to adjust the third and fourth line of the PREBATCH script to reflect your instrument's lowest note and the octave to start with. If you use "F#" and 4 for the values, and your files are named "Piano_1", etc., the first file will be named "Piano_F4#". If you'd rather see notes like "C#1" instead of "C1#" you can add comment marks (two forward slashes) at the start of the lines before the "return" line at the end of MAIN window. They are commented to show what they do. // -------------------------------------- PREBATCH -------------------------------------- // ADJUST THE FOLLOWING VARIABLES AS NEEDED: startNote = "A" ; // use the format "C" or "C#"... startOctave = 1 ; // this is the lowest octave on this instrument. // DO NOT CHANGE BELOW HERE! startNote = startNote.toUpperCase() ; noteArr = ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"] ; octArr = noteArr ; // counter vars (do not change): startIndex = noteArr.indexOf( startNote ) ; if (startNote == "A") { octTest = startOctave - 1 ; } else { octTest = startOctave ; } for ( let h = 0; h < startIndex; h++ ) { x = noteArr.shift() ; noteArr.push( x ) ; } // -------------------------------------- MAIN -------------------------------------- // SAMPLE FILENAME IN FORM: Instrument<number> (e.g., "Piano_1", "piano5", etc.) // YOUR SAMPLE FILENAME NUMBERS SHOULD START WITH 1 AND BE CONSECUTIVELY NUMBERED. // INSTRUMENT NAME CAN BE ANY PATTERN, BUT NO NUMBERS ALLOWED IN INSTRUMENT NAME PART. name = item.newBasename ; baseName = /^[^\d]+/.exec( name ) ; idx = app.currentIndex ; noteNum = idx ; if ( idx >= 12 ) { noteNum = (idx % 12) ; } if ( noteArr[noteNum] == "A" ) { octTest++ ; } newName = baseName + noteArr[noteNum] + octTest ; // The following line moves the sharp sign to the end: newName = newName.replace( /(\#)(\d$)/, "$2$1" ) ; // <--- CAN BE COMMENTED OUT (// AT START) // And this one puts a space at the end if there's no sharp: newName = newName.replace( /(\d)$/, "$1 " ) ; // <--- CAN BE COMMENTED OUT return newName ; // --------------------------------------------------------------------- That's it! Screenshot: https://drive.google.com/file/d/1zSORowuJWx4i2s_ FO_Dn-o-JLG-XCj1X/view?usp=sharing Best, DF |