LinJam.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. ==============================================================================
  3. LinJam.h
  4. Created: 24 May 2014 5:03:01pm
  5. Author: me
  6. ==============================================================================
  7. */
  8. #ifndef _LINJAM_H_
  9. #define _LINJAM_H_
  10. #ifdef _WIN32
  11. # include <windows.h>
  12. # include <stdio.h>
  13. # include <WDL/string.h>
  14. # include <WDL/ptrlist.h>
  15. # include <ninjam/njasiodrv/njasiodrv_if.h>
  16. #endif // _WIN32
  17. // NOTE: the GetLocalChannelName() function as well as
  18. // the NJClient and audioStreamer enums require libninjam v0.07 headers
  19. #include <ninjam/audiostream.h>
  20. #include <ninjam/njclient.h>
  21. #include <ninjam/njmisc.h>
  22. #include "JuceHeader.h"
  23. #include "LinJamConfig.h"
  24. #include "MainContent.h"
  25. class LinJam
  26. {
  27. friend class LinJamApplication ;
  28. friend class LinJamConfig ;
  29. friend class License ; // TODO: needs access to config object (issue #62)
  30. friend class Login ; // TODO: needs access to config object (issue #62)
  31. #if DEBUG
  32. friend class Trace ;
  33. #endif // DEBUG
  34. public:
  35. // state methods
  36. static void Connect() ;
  37. static void Disconnect() ;
  38. static void Shutdown() ;
  39. // getters/setters
  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 ConfigPending() ;
  48. static void ConfigDismissed() ;
  49. private:
  50. static NJClient* Client ;
  51. static MainContent* Gui ;
  52. static LinJamConfig* Config ;
  53. static audioStreamer* Audio ;
  54. static bool IsAudioInitialized ;
  55. static Value IsAudioEnabled ;
  56. static SortedSet<int> FreeAudioSources ;
  57. static SortedSet<int> FreeAudioSourcePairs ;
  58. static double GuiBeatOffset ;
  59. static File SessionDir ;
  60. static Value Status ;
  61. static String PrevRecordingTime ;
  62. // extension to NJClient::ConnectionStatus
  63. enum LinJamStatus { LINJAM_STATUS_INIT = -9 ,
  64. LINJAM_STATUS_AUDIOERROR = -8 ,
  65. LINJAM_STATUS_CONFIGPENDING = -7 ,
  66. LINJAM_STATUS_READY = -6 ,
  67. LINJAM_STATUS_LICENSEPENDING = -5 ,
  68. LINJAM_STATUS_ROOMFULL = -4 } ;
  69. // NJC_STATUS_DISCONNECTED = -3 // NJClient::ConnectionStatus
  70. // NJC_STATUS_INVALIDAUTH = -2 // NJClient::ConnectionStatus
  71. // NJC_STATUS_CANTCONNECT = -1 // NJClient::ConnectionStatus
  72. // NJC_STATUS_OK = 0 // NJClient::ConnectionStatus
  73. // NJC_STATUS_PRECONNECT = 1 // NJClient::ConnectionStatus
  74. // initialization methods
  75. static bool Initialize(NJClient* nj_client , MainContent* main_content ,
  76. const String& args ) ;
  77. static void InitializeAudio() ;
  78. static void ConfigureInitialChannels() ;
  79. static bool PrepareSessionDirectory() ;
  80. static void ConfigureNinjam() ;
  81. static void CleanSessionDir() ;
  82. // NJClient callbacks
  83. static int OnLicense(int user32 , char* license_text) ;
  84. static void OnChatmsg(int user32 , NJClient* instance ,
  85. const char** parms , int nparms ) ;
  86. static void OnSamples(float** input_buffer , int n_input_channels ,
  87. float** output_buffer , int n_output_channels ,
  88. int n_samples , int sample_rate ) ;
  89. // NJClient runtime routines
  90. static void HandleTimer(int timer_id) ;
  91. static void UpdateStatus() ;
  92. static void PumpClient() ;
  93. static void HandleStatusChanged() ;
  94. static void HandleUserInfoChanged() ;
  95. static void UpdateGuiHighPriority() ;
  96. static void UpdateGuiLowPriority() ;
  97. static void UpdateLoopProgress() ;
  98. static void UpdateVuMeters() ;
  99. static void UpdateRecordingTime() ;
  100. // GUI event handlers
  101. static void ConfigureSubscriptions() ;
  102. // NJClient config helpers
  103. static int GetNumAudioSources() ;
  104. static int GetNumLocalChannels() ;
  105. static int GetNumVacantChannels() ;
  106. static int GetVacantLocalChannelIdx() ;
  107. static String GetStoredChannelName( ValueTree channel_store) ;
  108. static String GetLocalChannelClientName( int channel_idx) ;
  109. static String GetRemoteUserName( int user_idx) ;
  110. static String GetRemoteChannelClientName(int user_idx , int channel_idx) ;
  111. static bool IsConfiguredChannel( int channel_idx) ;
  112. static double AddDecibels( double l_vu , double r_vu) ;
  113. static void ComputePannedVus( double pan , double* l_vu , double* r_vu) ;
  114. static void ScalePannedMonoVus( double vu_mono , double pan ,
  115. double* l_vu , double* r_vu) ;
  116. static float ComputeStereoPan( float pan , int stereo_status) ;
  117. static void UpdateRemoteUserState( ValueTree user_store , int user_idx ,
  118. bool should_ignore_user ) ;
  119. static void ConfigureMasterChannel( Identifier a_key) ;
  120. static void ConfigureMetroChannel( Identifier a_key) ;
  121. static void ConfigureLocalChannel( ValueTree channel_store , Identifier a_key) ;
  122. static void ConfigureRemoteChannel( ValueTree user_store ,
  123. ValueTree channel_store , Identifier a_key) ;
  124. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LinJam) ;
  125. } ;
  126. #endif // _LINJAM_H_