For discussion about setting up your studio and advice on the gear and equipment within it.
By martin Mon Jan 10, 2011 10:44 am
I just made a script that will sync your MPC to your computer's sample library, and after that trim the file names on the MPC to 16 characters. The good thing is that it will remember the original (long) file names, so it will only copy the samples that have actually changed since last time. If you (like me) have all your samples on your MPC's 16GB CF card, this is very important :wink:

This will only work on Unix systems like Mac OS X and Linux. Windows users need to use Cygwin. Use at your own risk.

Here's how to use it:

1. Create an empty file on your desktop, let's name it "mpcsync" (without ".txt" or something)

2. Edit that file and paste the following into it:

Code: Select all#!/bin/bash

# MODIFY THESE:
MPCFolder="/Volumes/MPC500 DISK"
Localfolder="/Users/martin/Musikmachen/samples"





num=1
length=16
# Rename all files to their original long form

cd $MPCFolder
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

for dir in $(find $MPCFolder/samples -type d); do
   cd $dir
   #echo "dir: $dir"
   
   
   for i in $dir/*.wav; do
      #echo "i: $i"
      searchstring="SHORT $i"
      linenumber=`grep -n "$searchstring" $MPCFolder/longfilenames.txt`
      linenumber=${linenumber/\:*/}

      #echo "$searchstring FOUND IN Line #${linenumber}"

      (( linenumber++ ))
      originalname=`sed -n ${linenumber}p $MPCFolder/longfilenames.txt`
      originalname=${originalname:5}

      #echo "Short Name: $i"
      #echo "Origi Name: $originalname"

      mv "$i" "${originalname}.temp"
   done
done

# echo "FIRST STEP DONE, ALL FILES ARE LONG AND HAVE .temp EXTENSION"

for dir in $(find $MPCFolder/samples -type d); do
   #cd $dir
   for i in $dir/*.wav.temp; do
      mv "$i" "${i/\.temp/}"
   done
done

IFS=$SAVEIFS

# Synchronize the folders using rsync. It will ignore hidden files/folders. The modify-window is needed on FAT32 in some cases.
rsync -avzti --delete-before --modify-window=3602 --ignore-errors --exclude='.*/' --exclude='.*' --progress "$Localfolder" "$MPCFolder/samples"

# Shorten file names:

cd $MPCFolder
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
mv $MPCFolder/longfilenames.txt $MPCFolder/longfilenames.old
touch $MPCFolder/longfilenames.txt

for dir in $(find $MPCFolder/samples -type d); do
   cd $dir
   #echo "dir: $dir"
   
   
   for i in $dir/*; do
      #echo "i: $i"
      FilenameWithoutDir=${i/$dir/}
      FilenameWithoutDir=${FilenameWithoutDir:1}


      FilenameWithoutExtension=${FilenameWithoutDir/\.*/}
      
      #echo "FileNameWithoutExtension: $FilenameWithoutExtension"
      Extension=${FilenameWithoutDir/$FilenameWithoutExtension/}
      #echo "Extension: $Extension"

      # echo "FilenameWithoutDir: $FilenameWithoutDir"

      newname=$FilenameWithoutExtension
      until [[ ! -f $newname$Extension ]]
      do
         (( sublen = length - ${#num} ))
         printf -v newname '%.*s%d' "$sublen" "$FilenameWithoutExtension" "$num"
         (( num++ ))
      done
      # echo "newname: $newname"
      #echo "Moving $FilenameWithoutDir -> $newname$Extension"
      
      # Save the original name so we can restore it next time
      echo "SHORT $dir/$newname$Extension" >> $MPCFolder/longfilenames.txt
      echo "LONG $i" >> $MPCFolder/longfilenames.txt
      mv "$FilenameWithoutDir" "$newname$Extension"
      num=1
   done
done
IFS=$SAVEIFS


Make sure you edit the MPCFolder and Localfolder line at the top. MPCFolder should point to your MPC hard drive / CF card when it's connected via USB. Localfolder should point to the sample library on your computer.
Save the file.

3. Open a Terminal (it's in /Applications/Utilities/) and run the following command:
Code: Select allchmod a+x ~/Desktop/mpcsync

The icon on your desktop will change.


You can now connect your MPC by USB (or plug in your card reader) and double-click the black icon on your desktop. After it closes, the sample folder on your MPC will be the same as the sample folder on your computer.
Last edited by martin on Tue Jan 11, 2011 4:56 pm, edited 3 times in total.
User avatar
By Pastor-of-Muppets Mon Jan 10, 2011 5:23 pm
martin wrote:3. Open a Terminal (it's in /Applications/Utilities/) and run the following command:
Code: Select allsudo chmod a+x ~/Desktop/mpcsync

It will ask for your password. Enter it and press enter. The icon on your desktop will turn into a black/gray rectangle.


Nice script - but there's no need to use "sudo" to make it executable, and in fact that won't work on many Linux systems (only on insane systems like Ubuntu and Wac OS X which think it's sensible to allow any commands to be run as root just by saying "sudo" ... all that does is encourage users who don't know better to run things as root ... so you might as well just have given them full root access anyway!)

Just do
Code: Select allchmod a+x ~/Desktop/mpcsync

without "sudo"
User avatar
By mp3 Mon Jan 10, 2011 5:40 pm
Big thanks for putting this work in homie!

Just one thing though, for the 1000/2500, you don't need to truncate to 16 characters. (not sure about other models). Those models will ignore anything between character 17 and the file extension. To avoid ambiguity, however, the filename must have at least one unique character in the first 16. What I do is just insert a 3 (or 4 for large directories) digit sequential number starting at character 14 (or 13, respectively), using a batch file renamer.
By martin Tue Jan 11, 2011 8:10 am
Pastor-of-Muppets wrote:Nice script - but there's no need to use "sudo" to make it executable

Thanks! I'm (positively) surprised to see a unix guy on here :) I changed the OP. I left the $IFS cause I don't really understand why I'm doing that. It used to give mistakes, I googled a little and found the $IFS stuff, then put it in.

eimer wrote:Nerds, lets get back to the beatmaking!

You are absolutely right! That's what it's all about. I just enjoy this kind of brainwork when my fingers are sore from slamming the pads :)

selecta jo wrote:the script is nice, but can you change the comments to english for the small percentage of people in the world who do not speak the deutsche sprache so well, please?

done :)


If you don't need filename truncating, you can just take the syncing part and delete the rest:
Code: Select all#!/bin/bash

# MODIFY THESE:
MPCFolder="/Volumes/MPC500 DISK"
Localfolder="/Users/martin/Musikmachen/samples"

rsync -avzti --delete-before --modify-window=3602 --ignore-errors --exclude='.*/' --exclude='.*' --progress "$Localfolder" "$MPCFolder/samples"
User avatar
By Pastor-of-Muppets Tue Jan 11, 2011 2:26 pm
martin wrote:
Pastor-of-Muppets wrote:Nice script - but there's no need to use "sudo" to make it executable

Thanks! I'm (positively) surprised to see a unix guy on here :)


:)

martin wrote:I changed the OP.


Cool - might want to remove this bit too: "It will ask for your password. Enter it and press enter." as it won't ask for a password if you don't use sudo

martin wrote:I left the $IFS cause I don't really understand why I'm doing that. It used to give mistakes, I googled a little and found the $IFS stuff, then put it in.


hehe

I'm pretty sure it could be avoided with some minor changes, which might make it simpler, I'll give it a try if I get time one evening this week
User avatar
By JUKE 179r Tue Jan 11, 2011 2:48 pm
eimer wrote:Nerds, lets get back to the beatmaking!












:lol:


:lol: