Esempio n. 1
0
 /**
  * a Constructor, usually called in the setup() method in your sketch to initialize and start the
  * library.
  *
  * @example portaTest
  * @param p
  */
 public PortaMod(PApplet p) {
   this.p = p;
   IBXM.SetMC(this);
   try {
     noteArrived = p.getClass().getMethod("grabNewdata", new Class[] {PortaMod.class});
   } catch (Exception e) {
     PApplet.println(e.getMessage());
   }
   try {
     noteArrivedB = p.getClass().getMethod("grabNewdataB", new Class[] {PortaMod.class});
   } catch (Exception e) {
     PApplet.println(e.getMessage());
   }
 }
Esempio n. 2
0
  private synchronized void init() throws SQLException {
    if (isClosed) return;

    // do tables exists?
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery(TABLE_NAMES_SELECT_STMT);

    ArrayList<String> missingTables = new ArrayList(TABLES.keySet());
    while (rs.next()) {
      String tableName = rs.getString("name");
      missingTables.remove(tableName);
    }

    for (String missingTable : missingTables) {
      try {
        Statement createStmt = conn.createStatement();
        // System.out.println("Adding table "+ missingTable);
        createStmt.executeUpdate(TABLES.get(missingTable));
        createStmt.close();

      } catch (Exception e) {
        System.err.println(e.getClass().getName() + ": " + e.getMessage());
      }
    }
  }
Esempio n. 3
0
  private static Header parseHeader(Node parent) throws XmlParserException {
    Header header = new Header();

    NodeList nodes = parent.getChildNodes();
    for (int nodeid = 0; nodeid < nodes.getLength(); ++nodeid) {
      Node node = nodes.item(nodeid);
      if (node.getNodeType() != Node.ELEMENT_NODE) continue;

      Element element = (Element) node;
      try {
        if (element.getTagName().equals("nrpeaks"))
          header.setNrPeaks(Integer.parseInt(element.getTextContent()));
        else if (element.getTagName().equals("date")) header.setDate(element.getTextContent());
        else if (element.getTagName().equals("owner")) header.setOwner(element.getTextContent());
        else if (element.getTagName().equals("description"))
          header.setDescription(element.getTextContent());
        else if (element.getTagName().equals("sets")) header.addSetInfos(parseSets(element));
        else if (element.getTagName().equals("measurements"))
          header.addMeasurementInfos(parseMeasurements(element));
        else if (element.getTagName().equals("annotations")) {
          Vector<Annotation> annotations = parseAnnotations(element);
          if (annotations != null)
            for (Annotation annotation : annotations) header.addAnnotation(annotation);
        }
      } catch (Exception e) {
        throw new XmlParserException(
            "Invalid value in header (" + element.getTagName() + "): '" + e.getMessage() + "'.");
      }
    }

    return header;
  }
Esempio n. 4
0
  protected void flushSerialBuffer() throws RunnerException, SerialException {
    // Cleanup the serial buffer
    try {
      Serial serialPort = new Serial();
      byte[] readBuffer;
      while (serialPort.available() > 0) {
        readBuffer = serialPort.readBytes();
        try {
          Thread.sleep(100);
        } catch (InterruptedException e) {
        }
      }

      serialPort.setDTR(false);
      serialPort.setRTS(false);

      try {
        Thread.sleep(100);
      } catch (InterruptedException e) {
      }

      serialPort.setDTR(true);
      serialPort.setRTS(true);

      serialPort.dispose();
    } catch (SerialNotFoundException e) {
      throw e;
    } catch (Exception e) {
      e.printStackTrace();
      throw new RunnerException(e.getMessage());
    }
  }
Esempio n. 5
0
 /** Mute audio (playback continues) */
 public void mute() {
   if (!muted) {
     try {
       muteCtrl.setValue(true);
       muted = true;
     } catch (Exception e) {
       PApplet.println(e.getMessage());
     }
   } else {
     try {
       muteCtrl.setValue(false);
       muted = false;
     } catch (Exception e) {
       PApplet.println(e.getMessage());
     }
   }
 }
Esempio n. 6
0
 /** setVol(float) adjusts overall volume. Checks for min/max limits to avoid crashes. */
 public void setVol(float newvol) {
   if (newvol > -40.0f && newvol < 6.020f) {
     try {
       volCtrl.setValue(newvol);
     } catch (Exception e) {
       PApplet.println(e.getMessage());
     }
   } else {
     PApplet.println(
         "Error - volume '" + newvol + "' is out of range. Must be between -40.0f and 6.020f!");
   }
 }
Esempio n. 7
0
 // Take a tree of files starting in a directory in a zip file
 // and copy them to a disk directory, recreating the tree.
 private int unpackZipFile(
     File inZipFile, String directory, String parent, boolean suppressFirstPathElement) {
   int count = 0;
   if (!inZipFile.exists()) return count;
   parent = parent.trim();
   if (!parent.endsWith(File.separator)) parent += File.separator;
   if (!directory.endsWith(File.separator)) directory += File.separator;
   File outFile = null;
   try {
     ZipFile zipFile = new ZipFile(inZipFile);
     Enumeration zipEntries = zipFile.entries();
     while (zipEntries.hasMoreElements()) {
       ZipEntry entry = (ZipEntry) zipEntries.nextElement();
       String name = entry.getName().replace('/', File.separatorChar);
       if (name.startsWith(directory)) {
         if (suppressFirstPathElement) name = name.substring(directory.length());
         outFile = new File(parent + name);
         // Create the directory, just in case
         if (name.indexOf(File.separatorChar) >= 0) {
           String p = name.substring(0, name.lastIndexOf(File.separatorChar) + 1);
           File dirFile = new File(parent + p);
           dirFile.mkdirs();
         }
         if (!entry.isDirectory()) {
           System.out.println("Installing " + outFile);
           // Copy the file
           BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(outFile));
           BufferedInputStream in = new BufferedInputStream(zipFile.getInputStream(entry));
           int size = 1024;
           int n = 0;
           byte[] b = new byte[size];
           while ((n = in.read(b, 0, size)) != -1) out.write(b, 0, n);
           in.close();
           out.flush();
           out.close();
           // Count the file
           count++;
         }
       }
     }
     zipFile.close();
   } catch (Exception e) {
     System.err.println("...an error occured while installing " + outFile);
     e.printStackTrace();
     System.err.println("Error copying " + outFile.getName() + "\n" + e.getMessage());
     return -count;
   }
   System.out.println(count + " files were installed.");
   return count;
 }
Esempio n. 8
0
  public boolean process(String[] args, BytecodeReader reader, JavaParser parser) {
    program.initBytecodeReader(reader);
    program.initJavaParser(parser);

    initOptions();
    processArgs(args);

    Collection files = program.options().files();

    if (program.options().hasOption("-version")) {
      printVersion();
      return false;
    }
    if (program.options().hasOption("-help") || files.isEmpty()) {
      printUsage();
      return false;
    }

    try {
      for (Iterator iter = files.iterator(); iter.hasNext(); ) {
        String name = (String) iter.next();
        if (!new File(name).exists())
          System.err.println("WARNING: file \"" + name + "\" does not exist");
        program.addSourceFile(name);
      }

      for (Iterator iter = program.compilationUnitIterator(); iter.hasNext(); ) {
        CompilationUnit unit = (CompilationUnit) iter.next();
        if (unit.fromSource()) {
          Collection errors = unit.parseErrors();
          Collection warnings = new LinkedList();
          // compute static semantic errors when there are no parse errors or
          // the recover from parse errors option is specified
          if (errors.isEmpty() || program.options().hasOption("-recover"))
            unit.errorCheck(errors, warnings);
          if (!errors.isEmpty()) {
            processErrors(errors, unit);
            return false;
          } else {
            if (!warnings.isEmpty()) processWarnings(warnings, unit);
            processNoErrors(unit);
          }
        }
      }
    } catch (Exception e) {
      System.err.println(e.getMessage());
      e.printStackTrace();
    }
    return true;
  }
    /**
     * Get an input stream for a resource contained in the jar file
     *
     * @param name file name of the resource within the jar file
     * @return an input stream representing the resouce if it exists or null
     */
    public InputStream getResourceAsStream(String name) {

      if (zfile == null || hasChanged()) {
        update();
      }
      try {
        if (zfile == null) return null;
        ZipEntry e = zfile.getEntry(name);
        if (e != null) return zfile.getInputStream(e);
      } catch (Exception e) {
        if (verbose)
          System.err.println("RJavaClassLoader$UnixJarFile: exception: " + e.getMessage());
      }
      return null;
    }
Esempio n. 10
0
 private boolean startLauncher(File dir) {
   try {
     Runtime rt = Runtime.getRuntime();
     ArrayList<String> command = new ArrayList<String>();
     command.add("java");
     command.add("-jar");
     command.add("Launcher.jar");
     String[] cmdarray = command.toArray(new String[command.size()]);
     Process proc = rt.exec(cmdarray, null, dir);
     return true;
   } catch (Exception ex) {
     System.err.println("Unable to start the Launcher program.\n" + ex.getMessage());
     return false;
   }
 }
 private InputStream getResourceStream(final File file, final String resourceName) {
   try {
     JarFile jarFile = this.jarFiles.get(file);
     if (jarFile == null && file.isDirectory()) {
       final File resource = new File(file, resourceName);
       if (resource.exists()) {
         return new FileInputStream(resource);
       }
     } else {
       if (jarFile == null) {
         if (!file.exists()) {
           return null;
         }
         jarFile = new JarFile(file);
         this.jarFiles.put(file, jarFile);
         jarFile = this.jarFiles.get(file);
       }
       final JarEntry entry = jarFile.getJarEntry(resourceName);
       if (entry != null) {
         return jarFile.getInputStream(entry);
       }
     }
   } catch (Exception e) {
     this.log(
         "Ignoring Exception "
             + e.getClass().getName()
             + ": "
             + e.getMessage()
             + " reading resource "
             + resourceName
             + " from "
             + file,
         3);
   }
   return null;
 }
Esempio n. 12
0
  /**
   * Load the MOD/XM/S3M module by filepath string. If the second parameter is false, the module
   * will not automatically start to play. The third parameter is the starting volume as a float
   * value between -40.0f and 6.020f. Start at the bottom if you want to fade a module in.
   *
   * @return int
   */
  public int doModLoad(String tune, boolean autostart, int startVol) {
    filepath = tune;
    modpath = tune;
    headerCheck(tune);
    PApplet.println("Header checked: " + modtype);

    if (loadSuccess > 0) {
      loadSuccess = 0;
    }

    InputStream file_input_stream = p.createInput(tune);

    try {
      if (playing == true) {
        player.stop();
        PApplet.println("stopped");
      }
      player = new Player(interpolation);

      player.set_module(Player.load_module(file_input_stream));
      file_input_stream.close();
      player.set_loop(true);
      player.receivebuffer(buffersize);
      if (autostart) {
        player.play();
        songStart = p.millis();
      }
      this.setGlobvol(startVol);
      PApplet.println(player.get_title());
      PApplet.println(player.song_duration);

      songLength = player.song_duration / 48000;
      infotext = new String[player.get_num_instruments()];

      for (int i = 0; i < (player.get_num_instruments()); i++) {
        infotext[i] = "";
        // store copies of all the instruments for changeSample
        Instrument tempinst_old = player.module.instruments[i];
        oldsamples.add(i, tempinst_old);
        if (player.ins_name(i) != null) {
          PApplet.println(player.ins_name(i));
          infotext[i] = player.ins_name(i);
        }
      }

      chantranspose = new int[player.get_num_channels()];
      for (int c = 0; c < player.get_num_channels(); c++) {
        chantranspose[c] = 0;
      }
      loopstart = new int[player.get_num_instruments()];
      looplength = new int[player.get_num_instruments()];
      origloopstart = new int[player.get_num_instruments()];
      origlooplength = new int[player.get_num_instruments()];
      sampledatalength = new int[player.get_num_instruments()];
      for (int ins = 0; ins < player.get_num_instruments(); ins++) {
        // initialise loopinfo arrays
        origloopstart[ins] = 0;
        origlooplength[ins] = 0;
        sampledatalength[ins] = player.module.instruments[ins].samples[0].sample_data_length;
        // store initial loop info for loopReset
        // System.out.println("Orig start: " +
        // player.module.instruments[ins].samples[0].loop_start);
        // System.out.println("Orig length: "
        // +player.module.instruments[ins].samples[0].loop_length);
        origloopstart[ins] = player.module.instruments[ins].samples[0].loop_start;
        origlooplength[ins] = player.module.instruments[ins].samples[0].loop_length;
      }

      PApplet.println("Channels:" + player.get_num_channels());
      // PApplet.println(player.output_line.getControls());

      try {
        // volCtrl = (FloatControl) player.output_line.getControl(FloatControl.Type.MASTER_GAIN);
        // volCtrl.setValue(startVol);
      } catch (Exception e) {
        PApplet.println(
            "Mystery javasound failure lucky dip! This week's prize: " + e.getMessage());
      }

      try {
        muteCtrl = (BooleanControl) player.output_line.getControl(BooleanControl.Type.MUTE);
      } catch (Exception e) {
        PApplet.println(e.getMessage());
      }
      /*			for (int i=0; i < numchannels; i++){
      	globvol = startVol;
      	try {
      		player.ibxm.channels[i].chanvol_override = startVol;
      	} catch (Exception e) {
      		// TODO Auto-generated catch block
      		e.printStackTrace();
      	}
      }*/

      title = player.get_title();
      numchannels = player.get_num_channels();
      jamnote = new int[player.get_num_channels()];
      jaminst = new int[player.get_num_channels()];
      for (int c = 0; c < player.get_num_channels(); c++) {
        jamnote[c] = 0;
        jaminst[c] = 0;
      }
      numinstruments = player.get_num_instruments();
      numpatterns = player.ibxm.module.get_sequence_length();
      playing = true;
      loadSuccess = 1;
      initialtempo = player.get_bpm();
      bpmvalue = player.get_bpm();
      currentrowcount = player.ibxm.total_rows;
      endcount = 0;
      //		if (player.get_num_channels() > 0) {
      //			sequencecounter = 0;
      //			refreshpattern();
      //			displayCurrentpattern();
      //		}
    } catch (Exception e) {
      PApplet.println(e.getMessage());
      PApplet.println("Printing stack trace... ");
      e.printStackTrace();
    }
    return loadSuccess;
  }
Esempio n. 13
0
  protected boolean executeUploadCommand(Collection commandDownloader) throws RunnerException {
    firstErrorFound = false; // haven't found any errors yet
    secondErrorFound = false;
    notFoundError = false;
    int result = 0; // pre-initialized to quiet a bogus warning from jikes

    String userdir = System.getProperty("user.dir") + File.separator;

    try {
      String[] commandArray = new String[commandDownloader.size()];
      commandDownloader.toArray(commandArray);

      String avrBasePath;

      if (Base.isLinux()) {
        avrBasePath = new String(Base.getHardwarePath() + "/tools/");
      } else {
        avrBasePath = new String(Base.getHardwarePath() + "/tools/avr/bin/");
      }

      commandArray[0] = avrBasePath + commandArray[0];

      if (verbose || Preferences.getBoolean("upload.verbose")) {
        for (int i = 0; i < commandArray.length; i++) {
          System.out.print(commandArray[i] + " ");
        }
        System.out.println();
      }
      Process process = Runtime.getRuntime().exec(commandArray);
      new MessageSiphon(process.getInputStream(), this);
      new MessageSiphon(process.getErrorStream(), this);

      // wait for the process to finish.  if interrupted
      // before waitFor returns, continue waiting
      //
      boolean compiling = true;
      while (compiling) {
        try {
          result = process.waitFor();
          compiling = false;
        } catch (InterruptedException intExc) {
        }
      }
      if (exception != null) {
        exception.hideStackTrace();
        throw exception;
      }
      if (result != 0) return false;
    } catch (Exception e) {
      String msg = e.getMessage();
      if ((msg != null)
          && (msg.indexOf("uisp: not found") != -1)
          && (msg.indexOf("avrdude: not found") != -1)) {
        // System.err.println("uisp is missing");
        // JOptionPane.showMessageDialog(editor.base,
        //                              "Could not find the compiler.\n" +
        //                              "uisp is missing from your PATH,\n" +
        //                              "see readme.txt for help.",
        //                              "Compiler error",
        //                              JOptionPane.ERROR_MESSAGE);
        return false;
      } else {
        e.printStackTrace();
        result = -1;
      }
    }
    // System.out.println("result2 is "+result);
    // if the result isn't a known, expected value it means that something
    // is fairly wrong, one possibility is that jikes has crashed.
    //
    if (exception != null) throw exception;

    if ((result != 0) && (result != 1)) {
      exception = new RunnerException(SUPER_BADNESS);
      // editor.error(exception);
      // PdeBase.openURL(BUGS_URL);
      // throw new PdeException(SUPER_BADNESS);
    }

    return (result == 0); // ? true : false;
  }