Csound Csound-dev Csound-tekno Search About

[Csnd] Python help please

Date2011-08-24 15:31
From"Art Hunkins"
Subject[Csnd] Python help please
I've written a Python script for a new XO/Sugar activity for children 
(SamplePlay).
It includes 26 buttons that allow a user to select (from the Journal) up to 
26 audio
samples/loops to play. AFAIK, the "filename" must be sent to Csound as a
discrete variable, on its own channel (see below).

As a result, I've 26 iterations(!) (0-25) of the same basic code. I'd like
to simplify it if possible (the code itself works fine). Any suggestions 
from
you Python/Csound enthusiasts are very much welcomed. (The code references
Victor's csndsugui.py, but I don't think this is significant her

   self.path0 = "0"
  (up through)
   self.path25 = "0"

   self.jobject0 = None
  (through)
   self.jobject25 = None

 def choose0(self, widget):
   chooser = ObjectChooser(parent=self, what_filter=mime.GENERIC_TYPE_AUDIO)
   result = chooser.run()
   if result == gtk.RESPONSE_ACCEPT:
     self.jobject0 = chooser.get_selected_object()
     self.path0 = str(self.jobject0.get_file_path())
   else:
     self.jobject0 = None
     self.path0 = "0"
  (through)
def choose25(self, widget):
   chooser = ObjectChooser(parent=self, what_filter=mime.GENERIC_TYPE_AUDIO)
   result = chooser.run()
   if result == gtk.RESPONSE_ACCEPT:
     self.jobject25 = chooser.get_selected_object()
     self.path25 = str(self.jobject25.get_file_path())
   else:
     self.jobject25 = None
     self.path25 = "0"

def send_data(self):
   self.w.set_filechannel("file0", self.path0)
   self.w.set_filechannel("file1", self.path1)
  (through)
   self.w.set_filechannel("file24", self.path24)
   self.w.set_filechannel("file25", self.path25)


Hoping (as a Python novice) to be shown a more efficient way; I'm in the 
dark -

Art Hunkins



Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2011-08-24 16:13
FromOlivier Bélanger
SubjectRe: [Csnd] Python help please
self.path0 -> self.path25 must be a list where you store your paths:
Same thing for self.jobjects... (not sure you really need to keep references to those objects).

self.paths = ["0"]*26
self.jobjects = [None]*26

def choose(self, widget):
    which = something here to grab the order of "widget"
    ....
    self.paths[which] = str(self.jobjects[which].get_file_path())

def send_data(self):
    for i in range(26):
        self.w.set_filechannel("file%d" % i, self.paths[i])

Olivier

2011/8/24 Art Hunkins <abhunkin@uncg.edu>
I've written a Python script for a new XO/Sugar activity for children (SamplePlay).
It includes 26 buttons that allow a user to select (from the Journal) up to 26 audio
samples/loops to play. AFAIK, the "filename" must be sent to Csound as a
discrete variable, on its own channel (see below).

As a result, I've 26 iterations(!) (0-25) of the same basic code. I'd like
to simplify it if possible (the code itself works fine). Any suggestions from
you Python/Csound enthusiasts are very much welcomed. (The code references
Victor's csndsugui.py, but I don't think this is significant her

 self.path0 = "0"
 (up through)
 self.path25 = "0"

 self.jobject0 = None
 (through)
 self.jobject25 = None

def choose0(self, widget):
 chooser = ObjectChooser(parent=self, what_filter=mime.GENERIC_TYPE_AUDIO)
 result = chooser.run()
 if result == gtk.RESPONSE_ACCEPT:
   self.jobject0 = chooser.get_selected_object()
   self.path0 = str(self.jobject0.get_file_path())
 else:
   self.jobject0 = None
   self.path0 = "0"
 (through)
def choose25(self, widget):
 chooser = ObjectChooser(parent=self, what_filter=mime.GENERIC_TYPE_AUDIO)
 result = chooser.run()
 if result == gtk.RESPONSE_ACCEPT:
   self.jobject25 = chooser.get_selected_object()
   self.path25 = str(self.jobject25.get_file_path())
 else:
   self.jobject25 = None
   self.path25 = "0"

def send_data(self):
 self.w.set_filechannel("file0", self.path0)
 self.w.set_filechannel("file1", self.path1)
 (through)
 self.w.set_filechannel("file24", self.path24)
 self.w.set_filechannel("file25", self.path25)


Hoping (as a Python novice) to be shown a more efficient way; I'm in the dark -

Art Hunkins



Send bugs reports to the Sourceforge bug tracker
          https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"



Date2011-08-24 16:23
FromTarmo Johannes
SubjectRe: [Csnd] Python help please
Hello,

and another hint,  perhaps it is useful:
 if you play the audio samples  in csound with diskin, diskin2, diskin or soundin,  the filename can be given also as integer  number
like
aL,aR soundin 1

the number  " denotes the file soundin.filcod;" (from the manual).

If you put your files to the same directory as the csd and rename them soundin.1, soundin.2 etc
you can pass just the number and get rid from the business with strings - it is always easier to manipulate the  numbers.

tarmo

On Wednesday 24 August 2011 17:31:02 Art Hunkins wrote:
> I've written a Python script for a new XO/Sugar activity for children 
> (SamplePlay).
> It includes 26 buttons that allow a user to select (from the Journal) up to 
> 26 audio
> samples/loops to play. AFAIK, the "filename" must be sent to Csound as a
> discrete variable, on its own channel (see below).
> 
> As a result, I've 26 iterations(!) (0-25) of the same basic code. I'd like
> to simplify it if possible (the code itself works fine). Any suggestions 
> from
> you Python/Csound enthusiasts are very much welcomed. (The code references
> Victor's csndsugui.py, but I don't think this is significant her
> 
>    self.path0 = "0"
>   (up through)
>    self.path25 = "0"
> 
>    self.jobject0 = None
>   (through)
>    self.jobject25 = None
> 
>  def choose0(self, widget):
>    chooser = ObjectChooser(parent=self, what_filter=mime.GENERIC_TYPE_AUDIO)
>    result = chooser.run()
>    if result == gtk.RESPONSE_ACCEPT:
>      self.jobject0 = chooser.get_selected_object()
>      self.path0 = str(self.jobject0.get_file_path())
>    else:
>      self.jobject0 = None
>      self.path0 = "0"
>   (through)
> def choose25(self, widget):
>    chooser = ObjectChooser(parent=self, what_filter=mime.GENERIC_TYPE_AUDIO)
>    result = chooser.run()
>    if result == gtk.RESPONSE_ACCEPT:
>      self.jobject25 = chooser.get_selected_object()
>      self.path25 = str(self.jobject25.get_file_path())
>    else:
>      self.jobject25 = None
>      self.path25 = "0"
> 
> def send_data(self):
>    self.w.set_filechannel("file0", self.path0)
>    self.w.set_filechannel("file1", self.path1)
>   (through)
>    self.w.set_filechannel("file24", self.path24)
>    self.w.set_filechannel("file25", self.path25)
> 
> 
> Hoping (as a Python novice) to be shown a more efficient way; I'm in the 
> dark -
> 
> Art Hunkins
> 
> 
> 
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
> 
> 


Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"

Date2011-08-26 10:53
Frommantaraya36@gmail.com
SubjectRe: [Csnd] Python help please
Hi Art,

Additionally, you could add the index input to the choose function:

def choose (self, index, widget)

Cheers,
Andres

On Wed Aug 24 16:13:31 2011 Olivier Bélanger wrote:

self.path0 -> self.path25 must be a list where you store your paths:
Same thing for self.jobjects... (not sure you really need to keep references to those objects).

self.paths = ["0"]*26
self.jobjects = [None]*26

def choose(self, widget):
    which = something here to grab the order of "widget"
    ....
    self.paths[which] = str(self.jobjects[which].get_file_path())

def send_data(self):
    for i in range(26):
        self.w.set_filechannel("file%d" % i, self.paths[i])

Olivier

2011/8/24 Art Hunkins <abhunkin@uncg.edu>
I've written a Python script for a new XO/Sugar activity for children (SamplePlay).
It includes 26 buttons that allow a user to select (from the Journal) up to 26 audio
samples/loops to play. AFAIK, the "filename" must be sent to Csound as a
discrete variable, on its own channel (see below).

As a result, I've 26 iterations(!) (0-25) of the same basic code. I'd like
to simplify it if possible (the code itself works fine). Any suggestions from
you Python/Csound enthusiasts are very much welcomed. (The code references
Victor's csndsugui.py, but I don't think this is significant her

 self.path0 = "0"
 (up through)
 self.path25 = "0"

 self.jobject0 = None
 (through)
 self.jobject25 = None

def choose0(self, widget):
 chooser = ObjectChooser(parent=self, what_filter=mime.GENERIC_TYPE_AUDIO)
 result = chooser.run()
 if result == gtk.RESPONSE_ACCEPT:
   self.jobject0 = chooser.get_selected_object()
   self.path0 = str(self.jobject0.get_file_path())
 else:
   self.jobject0 = None
   self.path0 = "0"
 (through)
def choose25(self, widget):
 chooser = ObjectChooser(parent=self, what_filter=mime.GENERIC_TYPE_AUDIO)
 result = chooser.run()
 if result == gtk.RESPONSE_ACCEPT:
   self.jobject25 = chooser.get_selected_object()
   self.path25 = str(self.jobject25.get_file_path())
 else:
   self.jobject25 = None
   self.path25 = "0"

def send_data(self):
 self.w.set_filechannel("file0", self.path0)
 self.w.set_filechannel("file1", self.path1)
 (through)
 self.w.set_filechannel("file24", self.path24)
 self.w.set_filechannel("file25", self.path25)


Hoping (as a Python novice) to be shown a more efficient way; I'm in the dark -

Art Hunkins



Send bugs reports to the Sourceforge bug tracker
          https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"