void chat_addline(char *src, char *text) { WDL_String tmp; if (src && *src && !strncmp(text,"/me ",4)) { tmp.Set("* "); tmp.Append(src); tmp.Append(" "); char *p=text+3; while (*p == ' ') p++; tmp.Append(p); } else { if (src&&*src) { tmp.Set("<"); tmp.Append(src); tmp.Append("> "); } else if (src) { tmp.Set("*** "); } tmp.Append(text); } g_client_mutex.Enter(); if (m_append_text.Get()[0]) m_append_text.Append("\n"); m_append_text.Append(tmp.Get()); g_client_mutex.Leave(); }
bool audioStreamer_JACK::addOutputChannel() { char name[10]; snprintf(name, sizeof(name), "out%d", m_outnch+1); jack_port_t* port = jack_port_register (client, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); if (port) { jack_port_t** tmp = _out; jack_port_t** tmp2 = new jack_port_t*[m_outnch+1]; for (unsigned i=0; i < m_outnch; i++) tmp2[i] = tmp[i]; tmp2[m_outnch] = port; _process_lock.Enter(); _out = tmp2; _process_lock.Leave(); delete[] tmp; float **tmp3 = _outports; float **tmp4 = new float*[m_outnch+1]; _process_lock.Enter(); _outports = tmp4; m_outnch++; _process_lock.Leave(); delete[] tmp3; return true; } else { return false; } }
int audioStreamer_JACK::process( jack_nframes_t nframes ) { _process_lock.Enter(); for (unsigned i=0; i<m_innch; i++) { _inports[i] = (float *) jack_port_get_buffer(_in[i], nframes); } for (unsigned i=0; i<m_outnch; i++) { _outports[i] = (float *) jack_port_get_buffer(_out[i], nframes); } splproc(_inports, m_innch, _outports, m_outnch, nframes, jack_get_sample_rate(client)); _process_lock.Leave(); return 0; }
void chatRun(HWND hwndDlg) { WDL_String tmp; g_client_mutex.Enter(); tmp.Set(m_append_text.Get()); m_append_text.Set(""); g_client_mutex.Leave(); if (!tmp.Get()[0]) return; HWND m_hwnd=GetDlgItem(hwndDlg,IDC_CHATDISP); SCROLLINFO si={sizeof(si),SIF_RANGE|SIF_POS|SIF_TRACKPOS,}; GetScrollInfo(m_hwnd,SB_VERT,&si); { int oldsels,oldsele; SendMessage(m_hwnd,EM_GETSEL,(WPARAM)&oldsels,(LPARAM)&oldsele); char txt[32768]; if(strlen(tmp.Get())>sizeof(txt)-1) return; GetWindowText(m_hwnd,txt,sizeof(txt)-1); txt[sizeof(txt)-1]=0; while(strlen(txt)+strlen(tmp.Get())+4>sizeof(txt)) { char *p=txt; while(*p!=0 && *p!='\n') p++; if(*p==0) return; while (*p=='\n') p++; strcpy(txt,p); oldsels -= p-txt; oldsele -= p-txt; } if (oldsels < 0) oldsels=0; if (oldsele < 0) oldsele=0; if(txt[0]) strcat(txt,"\n"); strcat(txt,tmp.Get()); CHARFORMAT2 cf2; cf2.cbSize=sizeof(cf2); cf2.dwMask=CFM_LINK; cf2.dwEffects=0; SendMessage(m_hwnd,EM_SETCHARFORMAT,SCF_ALL,(LPARAM)&cf2); SetWindowText(m_hwnd,txt); GetWindowText(m_hwnd,txt,sizeof(txt)-1); txt[sizeof(txt)-1]=0; char *t=txt; char lt=' '; int sub=0; while (*t) { if (lt == ' ' || lt == '\n' || lt == '\r') { int isurl=0; if (!strnicmp(t,"http:",5)) isurl=5; else if (!strnicmp(t,"ftp:",4)) isurl=4; else if (!strnicmp(t,"www.",4)) isurl=4; if (isurl && t[isurl] != ' ' && t[isurl] != '\n' && t[isurl] != '\r' && t[isurl]) { int spos=t-txt-sub; t+=isurl; while (*t && *t != ' ' && *t != '\n' && *t != '\r') { t++; } SendMessage(m_hwnd,EM_SETSEL,spos,(t-txt)-sub); CHARFORMAT2 cf2; cf2.cbSize=sizeof(cf2); cf2.dwMask=CFM_LINK; cf2.dwEffects=CFE_LINK; SendMessage(m_hwnd,EM_SETCHARFORMAT,SCF_SELECTION,(LPARAM)&cf2); } } if (*t == '\n') sub++; if (*t) lt=*t++; } SendMessage(m_hwnd,EM_SETSEL,oldsels,oldsele); } if (GetFocus() == m_hwnd) { SendMessage(m_hwnd, WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION,si.nTrackPos),0); } else { GetScrollInfo(m_hwnd,SB_VERT,&si); SendMessage(m_hwnd, WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION,si.nMax),0); } }
void chatRun(HWND hwndDlg) { WDL_String tmp; g_client_mutex.Enter(); tmp.Set(m_append_text.Get()); m_append_text.Set(""); g_client_mutex.Leave(); if (!tmp.Get()[0]) return; SCROLLINFO si={sizeof(si),SIF_RANGE|SIF_POS|SIF_TRACKPOS,}; GetScrollInfo(g_chat_hwnd , SB_VERT , &si) ; { int oldsels,oldsele; SendMessage(g_chat_hwnd , EM_GETSEL , (WPARAM)&oldsels , (LPARAM)&oldsele) ; char txt[32768]; if(strlen(tmp.Get())>sizeof(txt)-1) return; GetWindowText(g_chat_hwnd , txt , sizeof(txt)-1) ; txt[sizeof(txt)-1]=0; while(strlen(txt)+strlen(tmp.Get())+4>sizeof(txt)) { char *p=txt; while(*p!=0 && *p!='\n') p++; if(*p==0) return; while (*p=='\n') p++; strcpy(txt,p); oldsels -= p-txt; oldsele -= p-txt; } if (oldsels < 0) oldsels=0; if (oldsele < 0) oldsele=0; if(txt[0]) strcat(txt,"\n"); strcat(txt,tmp.Get()); CHARFORMAT2 cf2; cf2.cbSize=sizeof(cf2); cf2.dwMask=CFM_LINK; cf2.dwEffects=0; SendMessage(g_chat_hwnd , EM_SETCHARFORMAT , SCF_ALL , (LPARAM)&cf2) ; SetWindowText(g_chat_hwnd , txt) ; GetWindowText(g_chat_hwnd , txt , sizeof(txt)-1) ; txt[sizeof(txt)-1]=0; #if COLOR_CHAT char *t = txt ; int sub=0 ; char lt = '\n' ; while (*t) { if (lt == '\n' || lt == '\r') { int usernameOffset = 0 ; bool isParseTokens ; bool isColorText ; if (!strnicmp(t , "<PM from " , 9)) // private chat (choose color per user) { usernameOffset = 9 ; isParseTokens = true ; } else if (!strnicmp(t , "<" , 1)) // user chat (choose color per user) { usernameOffset = 1 ; isParseTokens = true ; } else isParseTokens = isColorText = false ; int lineBegin ; int boldEnd ; int normalBegin ; int lineEnd ; char theUsername[256] ; if (isParseTokens) { // parse username token and set seperator pointers (<bold> normal) lineBegin = t - txt - sub ; char* usernameBegin = (t += usernameOffset) ; while (*t && *t != '\n' && *t != '\r' && *t != ' ') ++t ; boldEnd = t - txt - sub ; normalBegin = boldEnd + 1 ; int theUsernameLen = boldEnd - lineBegin - usernameOffset - 1 ; if (isColorText = theUsernameLen < 256) { strncpy(theUsername , usernameBegin , theUsernameLen) ; theUsername[theUsernameLen] = '\0' ; } while (*t && *t != '\n' && *t != '\r') ++t ; lineEnd = t - txt - sub ; } if (isColorText) { // choose color per user int chatColorIdx = TeamStream::GetChatColorIdxByName(theUsername) ; COLORREF color = TeamStream::Get_Chat_Color(chatColorIdx) ; // apply char formatting CHARFORMAT2 cf2 ; cf2.cbSize = sizeof(cf2) ; // bold text - sender name cf2.dwMask = CFM_COLOR | CFM_BOLD ; cf2.crTextColor = color ; cf2.dwEffects = CFE_BOLD ; SendMessage(g_chat_hwnd , EM_SETSEL , lineBegin , boldEnd) ; SendMessage(g_chat_hwnd , EM_SETCHARFORMAT , SCF_SELECTION , (LPARAM)&cf2) ; if (!cfg_color_names_only) { // normal text - everything after bold text cf2.dwMask = CFM_COLOR ; cf2.crTextColor = color ; SendMessage(g_chat_hwnd , EM_SETSEL , normalBegin , lineEnd) ; SendMessage(g_chat_hwnd , EM_SETCHARFORMAT , SCF_SELECTION , (LPARAM)&cf2) ; } } } // if terminator char if (*t == '\n') sub++ ; if (*t) lt = *t++ ; } // while // NOTE: the original link parser code was unnecessary it is sufficient to // send EM_AUTOURLDETECT to the richedit20 control (catches most protocols) // and set its EM_SETEVENTMASK to ENM_LINK to enable event messaging (in chatInit()) // the only advantage to the original approach is catching hand-typed links beginning // with "www." (but still didn't catch links like "github.com") so for this most part // it was just wasted cycles (especially seeing as click handling was not implemented) // still the original code could be built upon to parse hand-typed links that don't // specify a protocol but ending with ".com" ".org" etc. if anyone thinks this to be useful // or to allow only certain users to post clickable links (disable EM_AUTOURLDETECT) // if so we need to reset state here for the 2nd pass /* SendMessage(m_hwnd , EM_SETSEL , oldsels , oldsele) ; t = txt ; lt = ' ' ; sub = 0 ; // original link parser code was here -------> */ #endif COLOR_CHAT } if (GetFocus() == g_chat_hwnd) { SendMessage(g_chat_hwnd , WM_VSCROLL , MAKEWPARAM(SB_THUMBPOSITION , si.nTrackPos) , 0) ; } else { GetScrollInfo(g_chat_hwnd , SB_VERT , &si) ; SendMessage(g_chat_hwnd , WM_VSCROLL , MAKEWPARAM(SB_THUMBPOSITION , si.nMax) , 0) ; } }