LinJam.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #ifndef _LINJAM_H_
  2. #define _LINJAM_H_
  3. /* NOTE: the following refs require libninjam v0.07
  4. * function NJClient::GetLocalChannelName()
  5. * function audioStreamer::NewASIO()
  6. * function audioStreamer::NewALSA() override
  7. * function audioStreamer::GetASIODriverName()
  8. * function audioStreamer::getNInputChannels()
  9. * function audioStreamer::getSampleRate()
  10. * function audioStreamer::GetDsGuidByName()
  11. * function audioStreamer::GetDsNamesCSV()
  12. * enum audioStreamer::WinApi
  13. * enum audioStreamer::MacApi
  14. * enum audioStreamer::NixApi */
  15. #include <ninjam/audiostream.h>
  16. #include <ninjam/njclient.h>
  17. #include <ninjam/njmisc.h> // VAL2DB and DB2VAL
  18. #include "JuceHeader.h"
  19. #include "LinJamConfig.h"
  20. #include "MainContent.h"
  21. /**
  22. LinJam is the main app controller class
  23. many of the view components handle their own interactions
  24. but most of the business eventually flows through here
  25. */
  26. class LinJam
  27. {
  28. friend class LinJamApplication ;
  29. friend class LinJamConfig ;
  30. #if DEBUG
  31. friend class Trace ;
  32. #endif // DEBUG
  33. public:
  34. // state
  35. static void SignIn(String host_name , String login , String pass , bool is_anonymous) ;
  36. static void Connect() ;
  37. static void Disconnect() ;
  38. // getters/setters
  39. static ValueTree GetCredentials(String host_name) ;
  40. static bool IsAgreed() ;
  41. static SortedSet<int> GetFreeAudioSources() ;
  42. static SortedSet<int> GetFreeAudioSourcePairs() ;
  43. // GUI event handlers
  44. static bool AddLocalChannel( ValueTree channel_store) ;
  45. static void RemoveLocalChannel(ValueTree channel_store) ;
  46. static void SendChat( String chat_text) ;
  47. static void CleanSessionDir() ;
  48. private:
  49. class RoomSort
  50. {
  51. public:
  52. static int compareElements(ValueTree a_server_store , ValueTree another_server_store)
  53. {
  54. int n_clients_a = a_server_store .getChildWithName(CONFIG::CLIENTS_ID).getNumChildren() ;
  55. int n_clients_b = another_server_store.getChildWithName(CONFIG::CLIENTS_ID).getNumChildren() ;
  56. return (n_clients_a < n_clients_b) ? 1 :
  57. (n_clients_a == n_clients_b) ? 0 : -1 ;
  58. }
  59. } ;
  60. static NJClient* Client ;
  61. static MainContent* Gui ;
  62. static MultiTimer* Timer ;
  63. static LinJamConfig* Config ;
  64. static audioStreamer* Audio ;
  65. static String AutoJoinHost ;
  66. static Value Status ;
  67. static bool IsAudioInitialized ;
  68. static SortedSet<int> FreeAudioSources ;
  69. static SortedSet<int> FreeAudioSourcePairs ;
  70. static double GuiBeatOffset ;
  71. static File SessionDir ;
  72. static int RetryLogin ;
  73. static String PrevRecordingTime ;
  74. static URL PollUrl ;
  75. static ScopedPointer<RoomSort> RoomSorter ;
  76. // setup
  77. static bool Initialize(NJClient* nj_client , MainContent* main_content ,
  78. MultiTimer* multi_timer , const String& cli_args ) ;
  79. static bool PrepareSessionDirectory() ;
  80. static void ConfigureNinjam() ;
  81. static void ConfigureGui(const Identifier& a_key) ;
  82. static void ConfigureBlacklist() ;
  83. static bool InitializeAudio() ;
  84. static void ConfigureInitialChannels() ;
  85. static void Shutdown() ;
  86. // NJClient callbacks
  87. static int OnLicense(int user32 , char* license_text) ;
  88. static void OnChatmsg(int user32 , NJClient* instance ,
  89. const char** parms , int nparms ) ;
  90. static void OnSamples(float** input_buffer , int n_input_channels ,
  91. float** output_buffer , int n_output_channels ,
  92. int n_samples , int sample_rate ) ;
  93. // NJClient runtime routines
  94. static void HandleTimer(int timer_id) ;
  95. static void UpdateStatus() ;
  96. static void PumpClient() ;
  97. static void HandleStatusChanged() ;
  98. static void HandleUserInfoChanged() ;
  99. static void UpdateGuiHighPriority() ;
  100. static void UpdateGuiLowPriority() ;
  101. static void UpdateLoopProgress() ;
  102. static void UpdateVuMeters() ;
  103. static void UpdateRooms() ;
  104. static void UpdateRecordingTime() ;
  105. // NJClient configuration
  106. static void ConfigureAudio() ;
  107. static void ConfigureMasterChannel(Identifier a_key) ;
  108. static void ConfigureMetroChannel( Identifier a_key) ;
  109. static void ConfigureLocalChannel( ValueTree channel_store , Identifier a_key) ;
  110. static void ConfigureRemoteChannel(ValueTree user_store ,
  111. ValueTree channel_store , Identifier a_key) ;
  112. // audio signal helpers
  113. static double AddDecibels( double l_vu , double r_vu) ;
  114. static void ComputePannedVus( double pan , double* l_vu , double* r_vu) ;
  115. static void ScalePannedMonoVus(double vu_mono , double pan ,
  116. double* l_vu , double* r_vu) ;
  117. static float ClientPan( float pan , int stereo_status) ;
  118. // NJClient/audioStreamer helpers
  119. static int GetNumAudioSources() ;
  120. static int GetNumLocalChannels() ;
  121. static int GetNumVacantChannels() ;
  122. static int GetVacantLocalChannelIdx() ;
  123. static String GetStoredChannelName( ValueTree channel_store) ;
  124. static String GetLocalChannelClientName( int channel_idx) ;
  125. static String GetRemoteUserName( int user_idx) ;
  126. static String GetRemoteChannelClientName(int user_idx , int channel_idx) ;
  127. static bool IsConfiguredChannel( int channel_idx) ;
  128. static double GetChannelDb( int channel_idx) ;
  129. static double GetChannelDb( int user_idx , int channel_idx) ;
  130. // signalling
  131. static void SetPollUrl() ;
  132. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LinJam) ;
  133. } ;
  134. #endif // _LINJAM_H_