MainStarterWidget::MainStarterWidget() { QVBoxLayout* layout = new QVBoxLayout(this); QWidget* w; w = new QuickStartWidget(); connect(w, SIGNAL(startRadio(RadioStation)), SIGNAL(startRadio(RadioStation))); layout->addWidget(w); w = m_recentStationsWidget = new RecentStationsWidget(); connect(w, SIGNAL(startRadio(RadioStation)), SIGNAL(startRadio(RadioStation))); connect(w, SIGNAL(showMoreRecentStations()), SIGNAL(showMoreRecentStations())); layout->addWidget(w); w = new YourStationsWidget(); connect(w, SIGNAL(startRadio(RadioStation)), SIGNAL(startRadio(RadioStation))); layout->addWidget(w); w = new MoreStationsWidget(); connect(w, SIGNAL(combo()), SIGNAL(combo())); connect(w, SIGNAL(tags()), SIGNAL(yourTags())); connect(w, SIGNAL(friends()), SIGNAL(yourFriends())); connect(w, SIGNAL(playlists()), SIGNAL(yourPlaylists())); layout->addWidget(w); }
void Influence::interApply() { auto voter = simAgent<Voter>(voter_); auto friends = voter->friends(); auto infls = influencees(friends); // std::cout << "Voter " << voter << " applying influence to " << infls.size() << " (of " << friends.size() << ") friends\n"; for (auto &inf : infls) { inf.second->attemptInfluence(voter, drift_); } }
int FriendsService::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 4) qt_static_metacall(this, _c, _id, _a); _id -= 4; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< QVariant*>(_v) = friends(); break; } _id -= 1; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setFriends(*reinterpret_cast< QVariant*>(_v)); break; } _id -= 1; } else if (_c == QMetaObject::ResetProperty) { _id -= 1; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 1; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 1; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 1; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 1; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 1; } #endif // QT_NO_PROPERTIES return _id; }
int tester(void) { int i,j; int e = 0; fld = malloc(NROWS * sizeof(int *));/*[5][5] = { {1,6,11,16,21}, {2,7,12,17,22}, {3,8,13,18,23}, {4,9,14,19,24}, {5,10,15,20,25} };*/ if(fld == NULL){ printf("Oops, couldn't ``malloc''?"); return(1); } for(i=0; i<NROWS; i++){ fld[i] = malloc(NCOLS * sizeof(int)); if(fld[i] == NULL){ printf("Hmm, couldn't do the second-dimension ``malloc''."); return(1); } } /* Initialize the array! */ for(j=0;j<NROWS;j++){ for(i=0;i<NCOLS;i++){ fld[i][j] = e; e++; } } #ifdef TEST for(j=0;j<NROWS;j++){ for(i=0;i<NCOLS;i++){ printf("%d\t",fld[i][j]); if((i+1) == x) printf("\n"); } } #endif printf("About to test the printer function.\n\n"); viz(fld); /* Should show: 0 1 2 3 4 5 6 7 8 Or some similar such, depending on NCOLS and NROWS */ /* Kill all cells! They should be all 0's now.*/ for(j=0;j<NROWS;j++){ for(i=0;i<NCOLS;i++){ killf(i,j); } } viz(fld); /* Spawn all cells! They should be all 1's now.*/ for(j=0;j<NROWS;j++){ for(i=0;i<NCOLS;i++){ spawn(i,j); } } viz(fld); printf("A corner cell should have 3 live neighbours: %d\n", friends(0,0)); printf("A middle cell should have 8 live neighbours: %d\n", friends(1,1)); printf("A side cell should have 5 live neighbours: %d\n", friends(1,0)); printf("Goodbye\n\n"); /* Try some basic tests of the generator and rule. */ for(j=0;j<NROWS;j++){ for(i=0;i<NCOLS;i++){ killf(i,j); } } spawn(0,1); spawn(1,1); spawn(2,1); viz(fld); generator(1); viz(fld); generator(1); viz(fld); printf("\n\nDone testing.\n\n"); return(0); }
autoFeatureWeights FeatureWeights_computeRELIEF ( /////////////////////////////// // Parameters // /////////////////////////////// PatternList pp, // source pattern // Categories c, // source categories // long k // k(!) // ) { autoPatternList p = Data_copy (pp); autoFeatureWeights me = FeatureWeights_create (p -> nx); ///////////////////////////////// // Initial weights <- 0 // ///////////////////////////////// for (long i = 1; i <= p->nx; i++) { my fweights -> data [1] [i] = 0.0; } ///////////////////////////////// // Normalization // ///////////////////////////////// autoNUMvector <double> min (0L, p->nx - 1); autoNUMvector <double> max (0L, p->nx - 1); for (long x = 1; x <= p -> nx; x ++) { max [x] = p -> z [1] [x]; // BUG: this will just crash because of array index out of bounds min [x] = max [x]; } for (long y = 1; y <= p -> ny; y ++) { for (long x = 1; x <= p->nx; x++) { if (p->z[y][x] > max[x]) max[x] = p->z[y][x]; if (p->z[y][x] < min[x]) min[x] = p->z[y][x]; } } autoNUMvector <double> alfa (0L, p -> nx - 1); for (long x = 1; x <= p -> nx; x ++) { alfa [x] = max [x] - min [x]; // BUG: this will just crash because of array index out of bounds } for (long y = 1; y <= p->ny; y++) { for (long x = 1; x <= p->nx; x++) { if (alfa [x] != 0.0) { p->z[y][x] = (p->z[y][x] - min[x]) / alfa[x]; } else { p->z[y][x] = 0.0; } } } ///////////////////////////////// // Computing prior class probs // ///////////////////////////////// autoNUMvector <double> priors (0L, c->size - 1); // worst-case allocations autoNUMvector <long> classes (0L, c->size - 1);// autoNUMvector <long> enemies (0L, c->size - 1);// autoNUMvector <long> friends (0L, c->size - 1);// long nclasses = FeatureWeights_computePriors (c, classes.peek(), priors.peek()); Melder_assert (nclasses >= 2); ///////////////////////////////// // Updating the w.vector // ///////////////////////////////// for (long y = 1; y <= p -> ny; y ++) { long nfriends = KNN_kFriends (p.get(), p.get(), c, y, k, friends.peek()); long nenemies = KNN_kUniqueEnemies (p.get(), p.get(), c, y, nclasses - 1, enemies.peek()); if (nfriends && nenemies) { autoNUMvector <double> classps (0L, nenemies - 1); for (long eq = 0; eq < nenemies; eq ++) { for (long iq = 0; iq < nclasses; iq ++) { if (FeatureWeights_areFriends (c->at [enemies [eq]], c->at [classes [iq]])) { classps [eq] = priors [iq]; break; } } } for (long x = 1; x <= p -> nx; x ++) { double p1 = 0.0; double p2 = 0.0; for (long ec = 0; ec < nfriends; ec ++) { p1 += fabs (p -> z [y] [x] - p -> z [friends [ec]] [x]) / (p -> ny * nfriends); } for (long ec = 0; ec < nenemies; ec++) { p2 += (fabs (p->z[y][x] - p->z[enemies[ec]][x]) * classps[ec]) / p->ny; } my fweights -> data [1] [x] = my fweights -> data [1] [x] - p1 + p2; } } } return me; }
/* Prompt for a Last.FM radio station URI, providing kind of smart tab completion and a history. No return value, playback of the URI is started directly from here. */ void radioprompt(const char * prompt) { char * url, * decoded = NULL; struct prompt setup = { .prompt = prompt, .line = NULL, .history = uniq(slurp(rcpath("radio-history"))), .callback = radiocomplete, }; /* Get overall top tags. */ overall = overalltags(); /* Get user, friends and neighbors. */ users = neighbors(value(& rc, "username")); users = merge(users, friends(value(& rc, "username")), 0); users = append(users, value(& rc, "username")); /* Get top artists. */ artists = topartists(value(& rc, "username")); /* Read the line. */ url = readline(& setup); /* Free everything. */ purge(users); purge(artists); purge(overall); overall = users = artists = NULL; if(setup.history) purge(setup.history); decode(url, & decoded); station(decoded); free(decoded); } /* Callback for the radio prompt for smart completion of radio URIs. */ int radiocomplete(char * line, const unsigned max, int changed) { unsigned length = strlen(line), nsplt = 0, slash = 0, nres = 0; const char * match; char ** splt, * types [] = { "user", "usertags", "artist", "globaltags", "play", NULL }; /* Remove leading "lastfm://", if found. */ if(!strncasecmp(line, "lastfm://", 9)) { memmove(line, line + 9, 9); memset(line + 9, 0, max - (length -= 9)); } if(length > 0 && line[length - 1] == '/') { slash = !0; changed = !0; } splt = split(line, "/", & nsplt); if(!nsplt) { free(splt); return 0; } switch(nsplt + (slash ? 1 : 0)) { /* First level completions (user, usertags, artists, ...) */ case 1: /* Get next match from first level chunks and fill it in. */ if((match = nextmatch(types, changed ? splt[0] : NULL, & nres)) != NULL) { snprintf(line, max, "%s%s", match, nres == 1 ? "/" : ""); } break; /* Second level completions (user/$USER, globaltags/$TAG, ...) */ case 2: /* For URIs like "{user,usertags}/...". */ if(!strcmp(splt[0], "user") || !strcmp(splt[0], "usertags")) { /* Get next match for 2nd level user chunk (user) and fill it in. */ match = nextmatch(users, changed ? (slash ? "" : splt[1]) : NULL, & nres); if(match) snprintf(line, max, "%s/%s%s", splt[0], match, nres == 1 ? "/" : ""); } /* For URIs like "artist/...". */ else if(!strcmp(splt[0], "artist")) { /* Get next artist match for 2nd level. */ match = nextmatch(artists, changed ? (slash ? "" : splt[1]) : NULL, & nres); if(match) snprintf(line, max, "%s/%s%s", splt[0], match, nres == 1 ? "/" : ""); } /* For URIs like "globaltags/...". Simply tag completion applied here. */ else if(!strcmp(splt[0], "globaltags")) { char * lastchunk = strrchr(line, '/') + 1; popular = overalltags(); tagcomplete(lastchunk, max - (lastchunk - line), changed); purge(popular); } break; /* Third level completions (artist/$ARTIST/fans, ...) */ case 3: /* "user/$USER/{personal,neighbors,loved,recommended,playlist}" */ if(!strcmp(splt[0], "user")) { char * radios [] = { "personal", "neighbours", "loved", "recommended", "playlist", NULL }; /* Get next match for 3rd level chunk and fill it in. */ match = nextmatch(radios, changed ? (slash ? "" : splt[2]) : NULL, NULL); snprintf(line, max, "%s/%s/%s", splt[0], splt[1], match ? match : splt[2]); } /* "artist/$ARTIST/{fans,similarartists}" */ else if(!strcmp(splt[0], "artist")) { char * radios [] = { "fans", "similarartists", NULL }; /* Get next match for 3rd level chunk. */ match = nextmatch(radios, changed ? (slash ? "" : splt[2]) : NULL, NULL); snprintf(line, max, "%s/%s/%s", splt[0], splt[1], match ? match : splt[2]); } /* Simple tag completion for "usertags" stations. */ else if(!strcmp(splt[0], "usertags")) { char * lastchunk = strrchr(line, '/') + 1; popular = overalltags(); tagcomplete(lastchunk, max - (lastchunk - line), changed); purge(popular); } break; } while(nsplt--) free(splt[nsplt]); free(splt); return !0; }
void WebService::requestResult( Request *r ) { Q_ASSERT( r ); switch (r->type()) { case TypeHandshake: { //TODO mxcl before I refactored, the handshake success if block was still // executed, but the result code was set to an error, I considered this a // bug and hopefully I'll remember to ask someone if that is the case or not Handshake *handshake = static_cast<Handshake*>(r); Q_ASSERT( m_username == handshake->username() ); Q_ASSERT( m_password == handshake->password() ); if (handshake->succeeded()) { m_streamUrl = handshake->streamUrl(); // legacy m_isSubscriber = handshake->isSubscriber(); } if (handshake->isMessage()) QMessageBox::information( qApp->activeWindow(), tr( "Last.fm Information" ), handshake->message() ); emit handshakeResult( handshake ); break; } // these macros makes the code more readable #define CASE( T ) case Type##T: { T##Request *request = static_cast<T##Request*>(r); #define break } break CASE( ChangeStation ) StationUrl url = request->stationUrl(); QString name = request->stationName(); emit changeStationResult( request ); if (r->succeeded()) emit stationChanged( url, name ); break; CASE( SetTag ) emit setTagResult( request ); break; CASE( ProxyTest ) if ( request->succeeded() || request->resultCode() == Request_ProxyAuthenticationRequired ) { m_isAutoDetectedProxy = request->proxyUsed(); emit proxyTestResult( m_isAutoDetectedProxy, request->resultCode() ); } break; default: ; } /// these are emitted only for the currentUsername() switch (r->type()) { CASE( Love ) emit loved( request->track() ); break; CASE( UnLove ) emit unloved( request->track() ); break; CASE( Ban ) emit banned( request->track() ); break; CASE( UnBan ) emit unbanned( request->track() ); break; CASE( UserTags ) if (request->username() == currentUsername()) emit userTags( request->tags() ); break; CASE( DeleteFriend ) emit friendDeleted( request->deletedUsername() ); break; CASE( Friends ) emit friends( request->usernames() ); break; CASE( Neighbours ) emit neighbours( request->usernames() ); break; CASE( RecentTracks ) emit recentTracks( request->tracks() ); break; CASE( RecentlyLovedTracks ) emit recentLovedTracks( request->tracks() ); break; CASE( RecentlyBannedTracks ) emit recentBannedTracks( request->tracks() ); break; default: ; } #undef CASE #undef break if ( r->failed() && r->resultCode() != Request_ProxyAuthenticationRequired ) emit failure( r ); else emit success( r ); emit result( r ); if (r->autoDelete()) // do last in case one of the signals is queued r->deleteLater(); }