=== Minim Error === === Couldn't invoke the sketchPath method: null

I’ve been using the minim library for a program that writes songs according to instructions.

When I try to use AudioRecorder, I keep getting this error:
=== Minim Error === === Couldn't invoke the sketchPath method: null

and the further error:

=== Minim Error ===
=== Couldn't create an AudioRecorder for 426232.wav.

Minim was working fine before I added the recorder. I have

minim = new Minim(this);

In the setup() method, where it’s supposed to be, and further, using println(sketchPath()); does indeed print out the absolute path to the sketch.

Processing doesn’t seem to have a problem with the sketchPath() function, and Minim didn’t seem to either until I added the audioRecorder.

I’m including a shortened version of the program here. I’m not sure what I did wrong. The compile error comes up at recorder.beginRecord(); because for some reason Minim’s audio recorder isn’t working with the sketchPath method.

Any help would be really appreciated!

import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;

Minim minim;
AudioOutput out;
AudioRecorder recorder;



float timeOfSong;

int lengthOfSong = 48;
int songKey = (int) random(1, 12);
boolean open = true;

static ArrayList<kiNote> kiNotes = new ArrayList<kiNote>();

String[] notes = {"A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"};

void setup() {

  String songName = ""+month()+day()+hour()+minute()+".wav";

println(sketchPath());

minim = new Minim(this);

recorder = minim.createRecorder(out, songName);

//*******
//This is all just a long boring program where I have the song
//being written with the notes queued up.  Nothing about this section changed
//when I added the recorder
//*******

  out.resumeNotes();
}


void draw() {
  recorder.beginRecord();
  float dTime = millis();
  if(millis() > dTime + timeOfSong) {
  if(open) {
    recorder.endRecord();
    recorder.save().close();
   open = false; 
  }
  
  }
  
}
1 Like

i see several problems, not only the file / name / path / save,
also the timer …

please use the default dir /data/ for your files,
even minim does not support that in the processing way. ( auto create )
means manually create under your project a subdir data, and save the files in there
example:

import ddf.minim.*;
//import ddf.minim.analysis.*;
//import ddf.minim.effects.*;
//import ddf.minim.signals.*;
//import ddf.minim.spi.*;
import ddf.minim.ugens.*;

Minim minim;
AudioOutput out;
AudioRecorder recorder;

int lengthOfSong = 5;               // sec ?
long startTime, timeOfSong=lengthOfSong*1000;  // sec to millis
boolean open = true;

String[] notes = {"A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"};
String songName = "data/song_"; // create /data/ directory manually!!!

void setup() {
  size(512, 200, P2D);
  minim = new Minim(this);
  out = minim.getLineOut();

  songName += ""+year()+"_"+month()+"_"+day()+"_"+hour()+"_"+minute()+"_"+second()+".wav";  
  recorder = minim.createRecorder(out, songName);
  recorder.beginRecord();
  startTime = millis();                  // timer init here

  int songKey = (int) random(1, 12);
  String theNote = notes[songKey];
  println("play: "+theNote);
  out.playNote(0, 3, theNote);
}

void draw() {
  background( 200, 200, 0 );
  if (millis() > startTime + timeOfSong) {    // timer
    if (open) {
      recorder.endRecord();
      recorder.save();
      println("Done saving: "+songName);
      open = false;
    }
  }
  stroke( 0, 200, 0 );                      // graph
  for ( int i = 0; i < out.bufferSize() - 1; i++ ) {
    float x1  =  map( i, 0, out.bufferSize(), 0, width );
    float x2  =  map( i+1, 0, out.bufferSize(), 0, width );
    line( x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50);
    line( x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50);
  }
}

please:
next time you paste code fragments here, you test them first ( and clean them up )
and like when you want to add something like a timer, test it first in an extra project.

1 Like

Hey, my apologies. I noticed after I posted it that I had taken out the rest of the timer in the part that I abridged. I did a test with it without the record audio and it seemed ok for the moment, but the time doesn’t make a bit of sense there in the draw method without the rest of it.

I see that looks pretty messy. Thank you for writing, though, I appreciate very much.