old_contents: import Axon
  
  class Polyphoniser(Axon.AdaptiveCommsComponent.AdaptiveCommsComponent):
      polyphony = 8
      def __init__(self, **argd):
          super(Polyphoniser, self).__init__(**argd)
          self.voices = []
          for i in range(self.polyphony):
              self.addOutbox("voice%i" % i)
              self.voices.append(None)
  
      def main(self, **argd):
          while 1:
              if self.dataReady("inbox"):
                  address, arguments = self.recv("inbox")
                  address = address.split("/")[-1]
                  if address == "On":
                      noteNumber = arguments[0]
                      if None in self.voices:
                          index = self.voices.index(None)
                          self.voices[index] = noteNumber
                          self.send((address, arguments), "voice%i" % index)
                      else:
                          # Verbose - we ignore the note if the level of polyphony
                          # isn't high enough
                          pass
                  elif address == "Off":
                      noteNumber, frequency = arguments
                      if noteNumber in self.voices:
                          index = self.voices.index(noteNumber)
                          self.voices[index] = None
                          self.send((address, arguments), "voice%i" % index)
              if not self.anyReady():
                  self.pause()
              yield 1
  
  
new_contents: import Axon
  
  class Polyphoniser(Axon.AdaptiveCommsComponent.AdaptiveCommsComponent):
      polyphony = 8
      def __init__(self, **argd):
          super(Polyphoniser, self).__init__(**argd)
          self.voices = []
          for i in range(self.polyphony):
              self.addOutbox("voice%i" % i)
              self.voices.append(None)
  
      def main(self):
          while 1:
              if self.dataReady("inbox"):
                  address, arguments = self.recv("inbox")
                  address = address.split("/")[-1]
                  if address == "On":
                      noteNumber = arguments[0]
                      if None in self.voices:
                          index = self.voices.index(None)
                          self.voices[index] = noteNumber
                          self.send((address, arguments), "voice%i" % index)
                      else:
                          # Verbose - we ignore the note if the level of polyphony
                          # isn't high enough
                          pass
                  elif address == "Off":
                      noteNumber, frequency = arguments
                      if noteNumber in self.voices:
                          index = self.voices.index(noteNumber)
                          self.voices[index] = None
                          self.send((address, arguments), "voice%i" % index)
              if not self.anyReady():
                  self.pause()
              yield 1
  
  class Targetter(Axon.AdaptiveCommsComponent.AdaptiveCommsComponent):
      polyphony = 8
      def __init__(self, **argd):
          super(Targetter, self).__init__(**argd)
          for i in range(self.polyphony):
              self.addOutbox("voice%i" % i)
  
      def main(self):
          while 1:
              if self.dataReady("inbox"):
                  address, arguments = self.recv("inbox")
                  address = address.split("/")[-1]
                  if address == "On" or address == "Off":
                      index = arguments[0]
                      self.send((address, arguments), "voice%i" % index)
              if not self.anyReady():
                  self.pause()
              yield 1
  
subject: Add targetting polyphoniser, allowing note on and off messages to select which voice to play through. This allows things like samplers to be put together more easily.