Skip to content

Commit

Permalink
Move file storage into a subfolder
Browse files Browse the repository at this point in the history
Also fix a bug where adding spaces to the group name caused photos to be
taken.
  • Loading branch information
chennes committed Jun 2, 2015
1 parent e912cc9 commit 63b6888
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions Stop_Motion_Animation.pde
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,13 @@ void setupUserInterface () {
;

// This makes the spacebar activate the takePhoto() function...
cp5.mapKeyFor(new ControlKey() {public void keyEvent() {takePhoto();}}, ' ');
cp5.mapKeyFor(new ControlKey() {
public void keyEvent() {
if (! groupnameField.isFocus()) {
takePhoto();
}
}
}, ' ');

cp5.addTextlabel ("Tip2")
.setText ("HOLD DOWN <CTRL> TO SEE PREVIOUS FRAME")
Expand Down Expand Up @@ -251,7 +257,17 @@ public void takePhoto ()

// Create the filename:
groupName = groupnameField.getText();
String filename = createFilename (groupName, sceneNumber, numberOfFrames);
String[] parts = new String[3];
parts[0] = "Image Files";
parts[1] = groupName.replaceAll("[^a-zA-Z0-9\\-_]", "");
try {
sceneNumber = Integer.parseInt (sceneNumberField.getText());
} catch (NumberFormatException e) {
// If they didn't give us an integer...
sceneNumber = 1;
}
parts[2] = createFilename (groupName, sceneNumber, numberOfFrames);
String filename = join (parts,File.separator);
frame.save (filename);
lastFileName = filename;
print ("Wrote frame to ");
Expand Down Expand Up @@ -323,7 +339,10 @@ private void loadPrevious ()
void loadPreviousFromFile (File selection)
{
if (selection != null) {
imageSequence.clear();
numberOfFrames = 0;
String pathToFile = selection.getPath();
String filePath = pathToFile.substring(0,pathToFile.lastIndexOf(File.separator));
String filename = selection.toPath().getFileName().toString();

// We have to figure out the sequence:
Expand All @@ -340,7 +359,7 @@ void loadPreviousFromFile (File selection)
int loadingPhotoNumber = 1;
boolean lastLoadWasSuccessful = true;
while (lastLoadWasSuccessful) {
String loadFilename = createFilename (groupName, sceneNumber, loadingPhotoNumber);
String loadFilename = filePath + File.separator + createFilename (groupName, sceneNumber, loadingPhotoNumber);
PImage frame = loadImage (loadFilename);
if (frame == null) {
lastLoadWasSuccessful = false;
Expand Down

0 comments on commit 63b6888

Please sign in to comment.