home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / arts / gslschedule.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  6.9 KB  |  263 lines

  1.    /*
  2.  
  3.     Copyright (C) 2000-2002 Stefan Westerfeld
  4.                             stefan@space.twc.de
  5.  
  6.     This library is free software; you can redistribute it and/or
  7.     modify it under the terms of the GNU Library General Public
  8.     License as published by the Free Software Foundation; either
  9.     version 2 of the License, or (at your option) any later version.
  10.   
  11.     This library is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.     Library General Public License for more details.
  15.    
  16.     You should have received a copy of the GNU Library General Public License
  17.     along with this library; see the file COPYING.LIB.  If not, write to
  18.     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19.     Boston, MA 02111-1307, USA.
  20.  
  21.     */
  22.  
  23. #ifndef ARTS_GSLSCHEDULE_H
  24. #define ARTS_GSLSCHEDULE_H
  25.  
  26. #include "artsflow.h"
  27. #include "flowsystem.h"
  28. #include <gsl/gsldefs.h>
  29. #include <string>
  30. #include <list>
  31.  
  32. /*
  33.  * BC - Status (2002-03-08): Port, AudioPort, MultiPort, StdFlowSystem,
  34.  *                           StdScheduleNode
  35.  *
  36.  * None of these classes is considered part of the public API. Do NOT use it
  37.  * in your apps. These are part of the implementation of libartsflow's
  38.  * StdFlowSystem, and subject to change with the needs of it.
  39.  *
  40.  * If you want to access flowsystem functionality, do so over the core.idl
  41.  * specified flowsystem interface, (object)->_node() or stuff in mcop/connect.h.
  42.  */
  43.  
  44. namespace Arts {
  45.  
  46. class StdScheduleNode;
  47.  
  48. class Port {
  49.     friend class VPort;                // TODO: debugging, remove me when it works?
  50.     friend class VPortConnection;    // TODO: debugging, remove me when it works?
  51. protected:
  52.     std::string _name;
  53. public:
  54.     void *_ptr;
  55. public:                // FIXME: GSL
  56.     AttributeType _flags;
  57.     StdScheduleNode *parent;
  58.  
  59.     // each port has a virtual port, which allows port redirection
  60.     class VPort *_vport;
  61.  
  62.     // dynamic ports are created to implement multiports
  63.     bool _dynamicPort;
  64.  
  65.     // functionality to remove all connections automatically as soon as
  66.     // the module gets destroyed
  67.     std::list<Port *> autoDisconnect;
  68.  
  69.     /**
  70.      * call these from your (dis)connect implementation as soon as a the
  71.      * port gets (dis)connected to some other port (only one call per
  72.      * connection: destinationport->addAutoDisconnect(sourceport), not
  73.      * for the other direction)
  74.      */
  75.     void addAutoDisconnect(Port *source);
  76.     void removeAutoDisconnect(Port *source);
  77.  
  78. public:
  79.     Port(const std::string& name, void *ptr, long flags,
  80.                                   StdScheduleNode* parent);
  81.     virtual ~Port();
  82.  
  83.     inline VPort* vport()         { assert(_vport); return _vport; }
  84.     AttributeType flags();
  85.     std::string name();
  86.     void setPtr(void *ptr);
  87.  
  88.     inline bool dynamicPort()    { return _dynamicPort; }
  89.     inline void setDynamicPort() { _dynamicPort = true; }
  90.  
  91.     virtual class AudioPort *audioPort();
  92.     virtual class ASyncPort *asyncPort();
  93.  
  94.     virtual void disconnectAll();
  95.     virtual void connect(Port *) = 0;
  96.     virtual void disconnect(Port *) = 0;
  97. };
  98.  
  99. class AudioPort : public Port {
  100. public:        // FIXME: GSL
  101.     AudioPort *source;
  102.  
  103. public:
  104.     StdScheduleNode *sourcemodule;
  105.     unsigned long destcount;
  106.     unsigned long gslEngineChannel;
  107.  
  108.     /* GSL */
  109.     bool gslIsConstant;
  110.     float gslConstantValue;
  111.  
  112.     AudioPort(const std::string& name,
  113.               void *ptr, long flags,StdScheduleNode *parent);
  114.     ~AudioPort();
  115.  
  116.     virtual class AudioPort *audioPort();
  117.  
  118.     void setFloatValue(float f);
  119.     void connect(Port *psource);
  120.     void disconnect(Port *psource);
  121. };
  122.  
  123. class MultiPort : public Port {
  124. protected:
  125.     struct Part {
  126.         AudioPort *src, *dest;
  127.     };
  128.  
  129.     std::list<Part> parts;
  130.     typedef float *float_ptr;
  131.     float **conns;
  132.     long nextID;
  133.     void initConns();
  134.  
  135. public:
  136.     MultiPort(const std::string& name,
  137.               void *ptr, long flags,StdScheduleNode *parent);
  138.     ~MultiPort();
  139.  
  140.     void connect(Port *port);
  141.     void disconnect(Port *port);
  142. };
  143.  
  144. class StdFlowSystem;
  145.  
  146. class StdScheduleNode :public ScheduleNode
  147. {
  148.     friend class StdFlowSystem;
  149.     bool running;
  150.     bool suspended;
  151.  
  152.     Object_skel *_object;
  153.     SynthModule_base *module;
  154.     StdFlowSystem *flowSystem;
  155.     std::list<Port *> ports;
  156.     AudioPort **inConn;
  157.     AudioPort **outConn;
  158.     unsigned long inConnCount, outConnCount;
  159.     typedef AudioPort *AudioPort_ptr;
  160.     QueryInitStreamFunc queryInitStreamFunc;
  161.  
  162.     void freeConn();
  163.     void rebuildConn();
  164.     void accessModule();
  165.  
  166.     static void gslProcess(GslModule *module, guint n_values);
  167.     public: /* TODO? */
  168.     Port *findPort(const std::string& name);
  169.  
  170. public:
  171.  
  172.     GslModule *gslModule;
  173.     bool gslRunning;
  174.  
  175.     /**
  176.      * this is used by StdFlowSystem::suspend() to mark nodes which
  177.      * have already been seen by the algorithm
  178.      */
  179.     bool suspendTag;
  180.  
  181.     StdScheduleNode(Object_skel *object, StdFlowSystem *flowSystem);
  182.     virtual ~StdScheduleNode();
  183.     void initStream(const std::string& name, void *ptr, long flags);
  184.     void addDynamicPort(Port *port);
  185.     void removeDynamicPort(Port *port);
  186.  
  187.     void start();
  188.     void stop();
  189.     void requireFlow();
  190.     void virtualize(const std::string& port, ScheduleNode *implNode,
  191.                                              const std::string& implPort);
  192.     void devirtualize(const std::string& port, ScheduleNode *implNode,
  193.                                                const std::string& implPort);
  194.  
  195.     // AutoSuspend stuff
  196.     AutoSuspendState suspendable();
  197.     void suspend();
  198.     void restart();
  199.  
  200.     void connect(const std::string& port, ScheduleNode *dest,
  201.                                           const std::string& destport);
  202.     void disconnect(const std::string& port, ScheduleNode *dest,
  203.                                              const std::string& destport);
  204.  
  205.     AttributeType queryFlags(const std::string& port);
  206.     void setFloatValue(const std::string& port, float value);
  207.  
  208.     Object_skel *object();
  209.     void *cast(const std::string &target);
  210.  
  211.     // used by StdSynthModule
  212.     unsigned long inputConnectionCount(const std::string& port);
  213.     unsigned long outputConnectionCount(const std::string& port);
  214.  
  215.     bool _connectionCountChanged;
  216.     inline bool connectionCountChanged() {
  217.         bool c = _connectionCountChanged;
  218.         _connectionCountChanged = false;
  219.         return c;
  220.     }
  221. };
  222.  
  223. class StdFlowSystem :public FlowSystem_impl
  224. {
  225. protected:
  226.     std::list<StdScheduleNode *> nodes;
  227.     bool _suspended;
  228.     bool needUpdateStarted;
  229. public:
  230.     StdFlowSystem();
  231.  
  232.     ScheduleNode *addObject(Object_skel *object);
  233.     void removeObject(ScheduleNode *node);
  234.  
  235.     /* AutoSuspend */
  236.     bool suspendable();
  237.     bool suspended();
  238.     void suspend();
  239.     void restart();
  240.  
  241.     /* remote accessibility */
  242.     void startObject(Object node);
  243.     void stopObject(Object node);
  244.     void connectObject(Object sourceObject, const std::string& sourcePort,
  245.                         Object destObject, const std::string& destPort);
  246.     void disconnectObject(Object sourceObject, const std::string& sourcePort,
  247.                         Object destObject, const std::string& destPort);
  248.     AttributeType queryFlags(Object node, const std::string& port);
  249.     void setFloatValue(Object node, const std::string& port, float value);
  250.  
  251.     FlowSystemReceiver createReceiver(Object object, const std::string &port,
  252.                                         FlowSystemSender sender);
  253.  
  254.     /* interface to StdScheduleNode */
  255.     void schedule(unsigned long samples);
  256.     void updateStarted();
  257.     void startedChanged();
  258. };
  259.  
  260. }
  261.  
  262. #endif
  263.