| Thanks
At 13:32 11/12/2007, you wrote:
>Is this the one? It may have been hacked it a little, it's all I could
>find. Cheers,
>
>Rory.
>
>
>
>
>
>
>import java.io.*;
>import javax.swing.JFrame;
>import java.io.File;
>import java.lang.System;
>import java.util.Properties;
>import javax.swing.JFileChooser;
>import javax.swing.filechooser.FileFilter;
>import csnd.*;
>
>/**
> *
> * @author Victor Lazzarini, 2005
> */
>
>public class CSDPlayer extends javax.swing.JFrame {
>
> private csperf cs;
> private Thread a;
> private JFileChooser choose;
> private boolean ready;
> private String csdfile = "";
> private javax.swing.JButton stopButton;
> private javax.swing.JButton pauseButton;
> private javax.swing.JButton playButton;
> private javax.swing.JButton openButton;
> private javax.swing.JButton editButton;
> private javax.swing.JButton quitButton;
> private javax.swing.JPanel mainPanel;
>
> public CSDPlayer( ) {
> initComponents();
> choose = new JFileChooser();
> FileFilter fil = new CSDFilter();
> choose.addChoosableFileFilter(fil);
> ready = false;
> }
>
> public CSDPlayer( String filename ) {
> csdfile = filename;
> initComponents();
> choose = new JFileChooser();
> FileFilter fil = new CSDFilter();
> choose.addChoosableFileFilter(fil);
> ready = false;
> }
>
> private void initComponents() {
> mainPanel = new javax.swing.JPanel();
> playButton = new javax.swing.JButton();
> pauseButton = new javax.swing.JButton();
> stopButton = new javax.swing.JButton();
> openButton = new javax.swing.JButton();
> editButton = new javax.swing.JButton();
> quitButton = new javax.swing.JButton();
>
> quitButton.setText("quit");
>
>
>setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
> playButton.setText("play");
> playButton.addActionListener(new java.awt.event.ActionListener() {
> public void actionPerformed(java.awt.event.ActionEvent evt) {
> playButtonActionPerformed(evt);
> }
> });
>
> mainPanel.add(playButton);
>
> pauseButton.setText("pause");
> pauseButton.addActionListener(new java.awt.event.ActionListener() {
> public void actionPerformed(java.awt.event.ActionEvent evt) {
> pauseButtonActionPerformed(evt);
> }
> });
>
> mainPanel.add(pauseButton);
>
> stopButton.setText("Stop");
> stopButton.addActionListener(new java.awt.event.ActionListener() {
> public void actionPerformed(java.awt.event.ActionEvent evt) {
> stopButtonActionPerformed(evt);
> }
> });
>
> mainPanel.add(stopButton);
>
> openButton.setText("open CSD");
> openButton.addActionListener(new java.awt.event.ActionListener() {
> public void actionPerformed(java.awt.event.ActionEvent evt) {
> openButtonActionPerformed(evt);
> }
> });
>
> mainPanel.add(openButton);
>
> editButton.setText("edit");
> editButton.addActionListener( new java.awt.event.ActionListener() {
> public void actionPerformed(
> java.awt.event.ActionEvent evt) {
> editButtonActionPerformed(evt);
> }
> });
> mainPanel.add(editButton);
>
> quitButton.setText("quit");
> quitButton.addActionListener(new java.awt.event.ActionListener() {
> public void actionPerformed(java.awt.event.ActionEvent evt) {
> quitButtonActionPerformed(evt);
> }
> });
>
> mainPanel.add(quitButton);
>
> getContentPane().add(mainPanel, java.awt.BorderLayout.NORTH);
> setTitle("CSDPlayer");
> pack();
> }
>
> private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {
> if( csdfile != "" )
> {
> TextEditor editor = new TextEditor( csdfile );
> editor.setVisible(true);
> }
> }
>
>
> private void quitButtonActionPerformed(java.awt.event.ActionEvent evt) {
> if (ready) {
> cs.stop();
> try {
> while (a.isAlive());
> } catch (Exception e) {
> java.lang.System.exit(0);
> }
> }
> java.lang.System.exit(0);
> }
>
> public void quit()
> {
> if (ready) {
> cs.stop();
> try {
> while (a.isAlive());
> } catch (Exception e) {
> java.lang.System.exit(0);
> }
> }
> java.lang.System.exit(0);
> }
>
> private void openButtonActionPerformed(java.awt.event.ActionEvent evt) {
> if (choose.showOpenDialog(this) != choose.CANCEL_OPTION) {
> File csd = choose.getSelectedFile();
> if (ready) cs.stop();
> csdfile = csd.getAbsolutePath();
> setTitle("CSDPlayer " + csd.getName());
> }
> }
>
> private void stopButtonActionPerformed(java.awt.event.ActionEvent evt) {
> if (ready) {
> cs.stop();
> }
> }
>
> private void playButtonActionPerformed(java.awt.event.ActionEvent evt) {
> if (ready)
> cs.play();
> else if (csdfile != "") {
> cs = new csperf(csdfile);
> a = new Thread(cs);
> a.start();
> ready = true;
> }
> }
>
> private void pauseButtonActionPerformed(java.awt.event.ActionEvent evt) {
> if (ready)
> cs.pause();
> }
>
> public static void main(String args[]) {
> java.awt.EventQueue.invokeLater(new Runnable() {
> public void run() {
> new CSDPlayer().setVisible(true);
> }
> });
> }
>
> public class csperf implements Runnable {
>
> Csound csp;
> boolean on;
> boolean pause;
> String csd;
>
> public csperf(String s) {
> csd = s;
> on = false;
> pause = false;
> csp = new Csound();
> }
>
> public void run() {
> try {
> int res = csp.Compile(csd, "-m0", "-d");
> if (res == 0) {
> on = true;
> while (on) {
> if (pause)
> csnd.csoundSleep(30);
> else if (csp.PerformBuffer() != 0)
> on = false;
> }
> }
> }
> catch (Exception e) {
> java.lang.System.err.println("Could not Perform...\n");
> java.lang.System.exit(1);
> }
> csp.Reset();
> ready = false;
> }
> public void stop() {
> on = false;
> }
> public void pause() {
> pause = !pause;
> }
> public void play() {
> pause = false;
> }
> public boolean isOn() {
> return on;
> }
> };
>
> public static class CSDFilter extends FileFilter {
> public boolean accept(File pathname) {
> if (pathname.isDirectory())
> return true;
> String csd = pathname.getAbsolutePath();
> if (csd.length() < 5)
> return false;
> return csd.toLowerCase().endsWith(".csd");
> }
> public String getDescription() {
> return "Unified Csound files";
> }
> };
>};
>
>-------------------------------------------------------------------------
>SF.Net email is sponsored by:
>Check out the new SourceForge.net Marketplace.
>It's the best place to buy or sell services for
>just about anything Open Source.
>http://sourceforge.net/services/buy/index.php_______________________________________________
>Csound-devel mailing list
>Csound-devel@lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/csound-devel
Victor Lazzarini
Music Technology Laboratory
Music Department
National University of Ireland, Maynooth
-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net |