LinJamConfig.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #ifndef _LINJAMCONFIG_H_
  2. #define _LINJAMCONFIG_H_
  3. #include "Constants.h"
  4. #include "JuceHeader.h"
  5. /**
  6. LinJamConfig is the model class
  7. it holds the runtime configuration via shared value holders
  8. and handles persistence via flat XML files
  9. it is also the controller for its shared value holders
  10. because the LinJmam controller class is currently static
  11. */
  12. class LinJamConfig : public Value::Listener , public ValueTree::Listener
  13. {
  14. friend class LinJam ;
  15. public:
  16. LinJamConfig() ;
  17. ~LinJamConfig() ;
  18. // validation
  19. static Identifier MakeHostId( String host) ;
  20. static Identifier MakeUserId( String channel_name) ;
  21. static Identifier MakeChannelId( int channel_idx) ;
  22. static String MakeStereoName( String channel_name , int stereo_status) ;
  23. static String TrimStereoName( String channel_name) ;
  24. static int ParseStereoStatus(String channel_name) ;
  25. static ValueTree NewChannel( String channel_name = CONFIG::DEFAULT_CHANNEL_NAME ,
  26. int channel_idx = CONFIG::DEFAULT_CHANNEL_IDX ) ;
  27. static Value GetValueHolder( ValueTree config_store , Identifier a_key) ;
  28. /* value holders (see Constants.h CONFIG_XML and CONFIG_DATATYPES_XML) */
  29. private:
  30. // config root (STORAGE_TYPES_KEY datatypes)
  31. ValueTree configRoot ; // STORAGE_ID node - parent of all nodes below
  32. public:
  33. // client config (GUI_KEY datatypes)
  34. ValueTree gui ; // GUI_ID node - gui-specific data
  35. // client config (CLIENT_KEY datatypes)
  36. ValueTree client ; // CLIENT_ID node - client-specific data
  37. // blacklist (BLACKLIST_KEY datatypes)
  38. ValueTree blacklist ; // BLACKLIST_ID node - blacklist-specific data
  39. // audio device config (AUDIO_KEY datatypes)
  40. ValueTree audio ; // AUDIO_KEY node - api-specific audio hardware initialization data
  41. // TODO: server[IS_AGREED_ID] exists only so OnLicense doesnt block (issue #14)
  42. // credentials (SERVER_KEY datatypes - IS_AGREED_ID is <server> node only)
  43. ValueTree server ; // SERVER_ID node - transient login credentials
  44. // credentials (list of SERVER_KEY datatypes)
  45. ValueTree servers ; // SERVERS_ID node - per-server credentials
  46. // peers (list of USERS_KEY datatypes - children are channels as below)
  47. ValueTree remoteUsers ; // REMOTES_ID node - per-peer data
  48. // channels (list of CHANNELS_KEY datatypes)
  49. ValueTree masterChannels ; // MASTERS_ID node - per-channel data (master and metro)
  50. ValueTree localChannels ; // LOCALS_ID node - per-channel data
  51. // remoteUsers[n] - per-channel data (each remoteUsers)
  52. private:
  53. File dataDir ;
  54. File configXmlFile ;
  55. Value dummyValue ;
  56. // setup
  57. void initialize() ;
  58. void establishSharedStore() ;
  59. void restoreVarTypeInfo( ValueTree config_store) ;
  60. void storeConfig() ;
  61. // validation
  62. ValueTree sanitizeConfig( ValueTree default_config , ValueTree stored_config) ;
  63. void validateServers() ;
  64. void validateUsers() ;
  65. void validateChannels(ValueTree channels) ;
  66. void sanitizeGui() ;
  67. bool validateConfig() ;
  68. bool isConfigValid() ;
  69. // getters/setters
  70. ValueTree addChannel( ValueTree channels_store , ValueTree new_store) ;
  71. void removeChannel( ValueTree channels_store , ValueTree channel_store) ;
  72. ValueTree getOrAddRemoteUser( String user_name) ;
  73. ValueTree getOrAddRemoteChannel(Identifier user_id , String channel_name ,
  74. int channel_idx = CONFIG::DEFAULT_CHANNEL_IDX) ;
  75. ValueTree getUserById( Identifier user_id) ;
  76. ValueTree getChannelById( Identifier channels_id , Identifier channel_id) ;
  77. ValueTree getChannelByIdx( ValueTree channels_store , int channel_idx) ;
  78. ValueTree getChannelByPairIdx( ValueTree channels_store , int pair_idx) ;
  79. ValueTree getChannelByName( ValueTree channels_store , String channel_name) ;
  80. ValueTree getUserMasterChannel( ValueTree user_store) ;
  81. void updateRemoteUserState(ValueTree user_store , int user_idx , bool should_rcv) ;
  82. void setCredentials( String host , String login , String pass ,
  83. bool is_anonymous ) ;
  84. ValueTree getCredentials( String host) ;
  85. void storeServer() ;
  86. ValueTree getServer( String host) ;
  87. void setStereo( ValueTree channel_store , int stereo_status) ;
  88. int setRemoteStereo( ValueTree user_store , ValueTree channel_store ,
  89. String prev_channel_name ) ;
  90. // event handlers
  91. void valueChanged( Value& value) override ;
  92. void valueTreePropertyChanged(ValueTree& node , const Identifier& key) override ;
  93. void valueTreeChildAdded( ValueTree& parent_node , ValueTree& node) override ;
  94. void valueTreeChildRemoved( ValueTree& parent_node , ValueTree& node ,
  95. int /*prev_idx*/ ) override ;
  96. // unused ValueTree::Listener interface implementations
  97. void valueTreeChildOrderChanged(ValueTree& /*parent_node*/ ,
  98. int /*prev_idx*/ , int /*curr_idx*/) override {} ;
  99. void valueTreeParentChanged( ValueTree& /*node*/) override {} ;
  100. void valueTreeRedirected( ValueTree& /*node*/) override {} ;
  101. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LinJamConfig) ;
  102. } ;
  103. #endif // _LINJAMCONFIG_H_