Exemple #1
0
FXint source_list_sort_reverse(const FXTreeItem* pa,const FXTreeItem* pb){
  const GMSource * const sa = static_cast<const GMSource*>(pa->getData());
  const GMSource * const sb = static_cast<const GMSource*>(pb->getData());
  if (sa->getType()>sb->getType()) return 1;
  else if (sa->getType()<sb->getType()) return -1;
  FXint a=0,b=0;
  if (begins_with_keyword(pa->getText())) a=FXMIN(pa->getText().length()-1,pa->getText().find(' ')+1);
  if (begins_with_keyword(pb->getText())) b=FXMIN(pb->getText().length()-1,pb->getText().find(' ')+1);
  return -compareversion(&pa->getText()[a],&pb->getText()[b]);
  }
long GMStreamSource::onCmdNewStation(FXObject*,FXSelector,void*){
  FXDialogBox dialog(GMPlayerManager::instance()->getMainWindow(),fxtr("New Internet Radio Station"),DECOR_TITLE|DECOR_BORDER|DECOR_RESIZE,0,0,0,0,0,0,0,0,0,0);
  GMPlayerManager::instance()->getMainWindow()->create_dialog_header(&dialog,fxtr("New Internet Radio Station"),fxtr("Specify url and description of new station"),nullptr);
  FXHorizontalFrame *closebox=new FXHorizontalFrame(&dialog,LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|PACK_UNIFORM_WIDTH,0,0,0,0);
  new GMButton(closebox,fxtr("C&reate"),nullptr,&dialog,FXDialogBox::ID_ACCEPT,BUTTON_INITIAL|BUTTON_DEFAULT|LAYOUT_RIGHT|FRAME_RAISED|FRAME_THICK,0,0,0,0, 15,15);
  new GMButton(closebox,fxtr("&Cancel"),nullptr,&dialog,FXDialogBox::ID_CANCEL,BUTTON_DEFAULT|LAYOUT_RIGHT|FRAME_RAISED|FRAME_THICK,0,0,0,0, 15,15);
  new FXSeparator(&dialog,SEPARATOR_GROOVE|LAYOUT_FILL_X|LAYOUT_SIDE_BOTTOM);
  FXVerticalFrame * main = new FXVerticalFrame(&dialog,LAYOUT_FILL_X|LAYOUT_FILL_Y,0,0,0,0,10,5,10,10);
  FXMatrix * matrix = new FXMatrix(main,2,LAYOUT_FILL_X|MATRIX_BY_COLUMNS);
  new FXLabel(matrix,fxtr("Location"),nullptr,LABEL_NORMAL|LAYOUT_RIGHT|LAYOUT_CENTER_Y);
  GMTextField * location_field = new GMTextField(matrix,40,nullptr,0,LAYOUT_FILL_X|LAYOUT_FILL_COLUMN|FRAME_SUNKEN|FRAME_THICK);
  new FXLabel(matrix,fxtr("Description"),nullptr,LABEL_NORMAL|LAYOUT_RIGHT|LAYOUT_CENTER_Y);
  GMTextField * description_field = new GMTextField(matrix,30,nullptr,0,LAYOUT_FILL_X|LAYOUT_FILL_COLUMN|FRAME_SUNKEN|FRAME_THICK);
  new FXLabel(matrix,fxtr("Tag"),nullptr,LABEL_NORMAL|LAYOUT_RIGHT|LAYOUT_CENTER_Y);
  GMComboBox * tagbox = new GMComboBox(matrix,20,nullptr,0,LAYOUT_FILL_X|FRAME_LINE);
  db->listTags(tagbox);
  tagbox->setSortFunc(genre_list_sort);
  tagbox->setNumVisible(FXMIN(10,tagbox->getNumItems()));
  tagbox->sortItems();
  tagbox->setCurrentItem(-1);
  if (dialog.execute()) {
    FXString url=location_field->getText().trim();
    FXString name=description_field->getText().trim();
    FXString genre=tagbox->getText().trim();
    if (!url.empty()) {
      if (genre.empty()) genre=fxtr("Untitled");
      db->insertStream(url,name,genre);
      GMPlayerManager::instance()->getTrackView()->refresh();
      }
    }
  return 1;
  }
FXival HttpInput::read(void * data,FXival count) {
  FXival n,t=0;
  FXuchar * p = (FXuchar*)data;

  /// Don't read past content
  if (client.getContentLength()>=0) {
    if (content_position>=client.getContentLength())
      return 0;
    else
      count=FXMIN((client.getContentLength()-content_position),count);
    }

  // Read from preview buffer
  if (preview_buffer.size()) {
    n=preview_buffer.read(p,count);
    if (0<n) { p+=n;count-=n; t+=n;}
    }

  // Regular Read
  if (icy_interval)
    n=icy_read(p,count);
  else
    n=client.readBody(p,count);

  if (n>0) {
    content_position+=n;
    t+=n;
    }
  return t;
  }
Exemple #4
0
// Called by the viewer to get bounds for this object
void FXGLVertices::bounds(FXRangef& box){
  if(vertexNumber){
    range.lower.x=range.upper.x=vertices[0].x;
    range.lower.y=range.upper.y=vertices[0].y;
    range.lower.z=range.upper.z=vertices[0].z;
    for(FXuint n=1; n<vertexNumber; n++){
      range.lower.x=FXMIN(range.lower.x, vertices[n].x);
      range.lower.y=FXMIN(range.lower.y, vertices[n].y);
      range.lower.z=FXMIN(range.lower.z, vertices[n].z);
      range.upper.x=FXMAX(range.upper.x, vertices[n].x);
      range.upper.y=FXMAX(range.upper.y, vertices[n].y);
      range.upper.z=FXMAX(range.upper.z, vertices[n].z);
      }
    }
  box.lower.x=position.x+range.lower.x; box.upper.x=position.x+range.upper.x;
  box.lower.y=position.y+range.lower.y; box.upper.y=position.y+range.upper.y;
  box.lower.z=position.z+range.lower.z; box.upper.z=position.z+range.upper.z;
  }
Exemple #5
0
// Construct list box with given caption, icon, message text, and with choices from newline separated strings
DirHistBox::DirHistBox(FXWindow* owner,const FXString& choices,FXuint opts,FXint x,FXint y,FXint w,FXint h):
        DialogBox(owner,"",opts,x,y,w,h,0,0,0,0, 0,0)
{
    register FXint n;
	FXHorizontalFrame* hor=new FXHorizontalFrame(this,FRAME_RAISED|FRAME_THICK|LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y,0,0,0,0, 0,0,0,0, 0,0);
    list=new FXList(hor,this,ID_CLICKED,LIST_BROWSESELECT|LAYOUT_FILL_Y|LAYOUT_FILL_X|HSCROLLING_OFF);
	list->setBackColor(this->getBackColor());
    n=list->fillItems(choices);
    list->setNumVisible(FXMIN(n,VISIBLE_LINES));
}
void AlphaBallControl::layout(){
  register FXint ww,hh,ss;
  ww=width-padleft-padright-(border<<1);
  hh=height-padtop-padbottom-(border<<1);
  ss=FXMAX(3,FXMIN(ww,hh));
  if(dial->getWidth()!=ss){
    dial->resize(ss,ss);
    updatedial();
    dial->render();
  }
  dialx=border+padleft+(ww-ss)/2;
  dialy=border+padtop+(hh-ss)/2;
  spottoxy(spotx,spoty,alphaxy[0],alphaxy[1]);
  flags&=~FLAG_DIRTY;
}
Exemple #7
0
FXbool PulseOutput::write(const void * b,FXuint nframes){
  FXASSERT(stream);
  const FXchar * buffer = reinterpret_cast<const FXchar*>(b);
  FXuint total = nframes*af.framesize();
  while(total) {

    if (pa_stream_get_state(stream)!=PA_STREAM_READY)
      return false;

    size_t nbytes = pa_stream_writable_size(stream);
    size_t n = FXMIN(total,nbytes);
    if (n==0) {
      //fxmessage("size %ld\n",nbytes);
      context->wait_plugin_events();
      continue;
      }
    pa_stream_write(stream,buffer,n,nullptr,0,PA_SEEK_RELATIVE);
    total-=n;
    buffer+=n;
    }
  return true;
  }
FXival HttpInput::preview(void*data,FXival count) {
  FXival n;

  preview_buffer.reserve(count);

  if (client.getContentLength()>=0) {
    if (content_position>=client.getContentLength())
      return -1;
    else
      count=FXMIN((client.getContentLength()-content_position),count);
    }

  if (icy_interval)
    n=icy_read(data,count);
  else
    n=client.readBody(data,count);

  if (n>0)
    preview_buffer.append(data,n);

  return -1;
  }
DecoderStatus VorbisDecoder::process(Packet * packet) {
  FXASSERT(packet);

#ifdef HAVE_VORBIS_PLUGIN
  FXfloat ** pcm=NULL;
  FXfloat * buf32=NULL;
#else // HAVE_TREMOR_PLUGIN
  FXint ** pcm=NULL;
  FXshort * buf32=NULL;
#endif

  FXint p,navail=0;

  FXint ngiven,ntotalsamples,nsamples,sample,c,s;

  FXbool  eos=packet->flags&FLAG_EOS;
  FXuint   id=packet->stream;
  FXlong  len=packet->stream_length;


  OggDecoder::process(packet);

  /// Init Decoder
  if (!has_dsp) {
    if (!init_decoder())
      return DecoderError;
    if (!has_dsp)
      return DecoderOk;
    }

  /// Find Stream Position
  if (stream_position==-1 && !find_stream_position())
    return DecoderOk;


  if (out) {
    navail = out->availableFrames();
    }

  while(get_next_packet()) {

    if (__unlikely(is_vorbis_header())) {
      GM_DEBUG_PRINT("[vorbis] unexpected vorbis header found. Resetting decoder\n");
      push_back_packet();
      reset_decoder();
      return DecoderOk;
      }

    if (vorbis_synthesis(&block,&op)==0)
      vorbis_synthesis_blockin(&dsp,&block);

    while((ngiven=vorbis_synthesis_pcmout(&dsp,&pcm))>0) {
      if (len>0) FXASSERT(stream_position+ngiven<=len);

      if (__unlikely(stream_position<stream_decode_offset)) {
        FXlong offset = FXMIN(ngiven,stream_decode_offset - stream_position);
        GM_DEBUG_PRINT("[vorbis] stream decode offset %ld. Skipping %ld of %ld \n",stream_decode_offset,offset,stream_decode_offset-stream_position);
        ngiven-=offset;
        stream_position+=offset;
        sample=offset;
        vorbis_synthesis_read(&dsp,offset);
        if (ngiven==0) continue;
        }
      else {
        sample=0;
        }

      for (ntotalsamples=ngiven;ntotalsamples>0;) {

        /// Get new buffer
        if (out==NULL) {
          out = engine->decoder->get_output_packet();
          if (out==NULL) return DecoderInterrupted;
          out->stream_position=stream_position;
          out->stream_length=len;
          out->af=af;
          navail = out->availableFrames();
          }

#ifdef HAVE_VORBIS_PLUGIN
        buf32 = out->flt();
#else // HAVE_TREMOR_PLUGIN
        buf32 = out->s16();
#endif
        /// Copy Samples
        nsamples = FXMIN(ntotalsamples,navail);
        for (p=0,s=sample;s<(nsamples+sample);s++){
          for (c=0;c<info.channels;c++,p++) {
#ifdef HAVE_VORBIS_PLUGIN
            buf32[p]=pcm[c][s];
#else
            buf32[p]=CLIP_TO_15(pcm[c][s]>>9);
#endif
            }
          }

        /// Update sample counts
        out->wroteFrames(nsamples);

        sample+=nsamples;
        navail-=nsamples;
        ntotalsamples-=nsamples;
        stream_position+=nsamples;

        /// Send out packet if full
        ///FIXME handle EOS.
        if (navail==0) {
          engine->output->post(out);
          out=NULL;
          }
        }
      vorbis_synthesis_read(&dsp,ngiven);
      }
    }

  if (eos) {
    if (out && out->numFrames())  {
      engine->output->post(out);
      out=NULL;
      }
    engine->output->post(new ControlEvent(End,id));
    }
  return DecoderOk;
  }
Exemple #10
0
void GMAudioPlayer::setPosition(FXuint position) {
  if (time.length>0) {
    seek(FXMIN(1.0,(position/(double)time.length)));
    }
  }
Exemple #11
0
FXint generic_name_sort_reverse(const FXListItem* pa,const FXListItem* pb){
  FXint a=0,b=0;
  if (begins_with_keyword(pa->getText())) a=FXMIN(pa->getText().length()-1,pa->getText().find(' ')+1);
  if (begins_with_keyword(pb->getText())) b=FXMIN(pb->getText().length()-1,pb->getText().find(' ')+1);
  return comparecase(&pb->getText()[b],&pa->getText()[a]);
  }
long GMStreamSource::onCmdEditStation(FXObject*,FXSelector,void*){
  GMTextField * location_field=nullptr;
  FXIntList tracks;
  GMPlayerManager::instance()->getTrackView()->getSelectedTracks(tracks);
  FXDialogBox dialog(GMPlayerManager::instance()->getMainWindow(),fxtr("Edit Internet Radio Station"),DECOR_TITLE|DECOR_BORDER|DECOR_RESIZE|DECOR_CLOSE,0,0,0,0,0,0,0,0,0,0);
  GMPlayerManager::instance()->getMainWindow()->create_dialog_header(&dialog,fxtr("Edit Internet Radio Station"),fxtr("Update url and description of station"),nullptr);
  FXHorizontalFrame *closebox=new FXHorizontalFrame(&dialog,LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|PACK_UNIFORM_WIDTH,0,0,0,0);
  new GMButton(closebox,fxtr("&Save"),nullptr,&dialog,FXDialogBox::ID_ACCEPT,BUTTON_INITIAL|BUTTON_DEFAULT|LAYOUT_RIGHT|FRAME_RAISED|FRAME_THICK,0,0,0,0, 15,15);
  new GMButton(closebox,fxtr("&Cancel"),nullptr,&dialog,FXDialogBox::ID_CANCEL,BUTTON_DEFAULT|LAYOUT_RIGHT|FRAME_RAISED|FRAME_THICK,0,0,0,0, 15,15);
  new FXSeparator(&dialog,SEPARATOR_GROOVE|LAYOUT_FILL_X|LAYOUT_SIDE_BOTTOM);
  FXVerticalFrame * main = new FXVerticalFrame(&dialog,LAYOUT_FILL_X|LAYOUT_FILL_Y,0,0,0,0,10,5,10,10);
  FXMatrix * matrix = new FXMatrix(main,2,LAYOUT_FILL_X|MATRIX_BY_COLUMNS);
  if (tracks.no()==1) {
    new FXLabel(matrix,fxtr("Location"),nullptr,LABEL_NORMAL|LAYOUT_RIGHT|LAYOUT_CENTER_Y);
    location_field = new GMTextField(matrix,40,nullptr,0,LAYOUT_FILL_X|LAYOUT_FILL_COLUMN|FRAME_SUNKEN|FRAME_THICK);
    }
  new FXLabel(matrix,fxtr("Description"),nullptr,LABEL_NORMAL|LAYOUT_RIGHT|LAYOUT_CENTER_Y);
  GMTextField * description_field = new GMTextField(matrix,30,nullptr,0,LAYOUT_FILL_X|LAYOUT_FILL_COLUMN|FRAME_SUNKEN|FRAME_THICK);
  new FXLabel(matrix,fxtr("Genre"),nullptr,LABEL_NORMAL|LAYOUT_RIGHT|LAYOUT_CENTER_Y);
  GMComboBox * tagbox = new GMComboBox(matrix,20,nullptr,0,LAYOUT_FILL_X|FRAME_LINE);
  db->listTags(tagbox);
  tagbox->setSortFunc(genre_list_sort);
  tagbox->setCurrentItem(-1);
  tagbox->setNumVisible(FXMIN(10,tagbox->getNumItems()));
  tagbox->sortItems();

  GMStream info;

  if (tracks.no()==1) {
    db->getStream(tracks[0],info);
    location_field->setText(info.url);
    description_field->setText(info.description);
    tagbox->setCurrentItem(tagbox->findItem(info.tag));
    }

  if (dialog.execute()) {
    FXbool changed=false;


    if (tracks.no()==1 && location_field->getText()!=info.url && !location_field->getText().empty()) {
      db->setStreamFilename(tracks[0],location_field->getText());
      changed=true;
      }

    if (description_field->getText()!=info.description && !description_field->getText().empty()){
      for (FXint i=0;i<tracks.no();i++)
        db->setStreamDescription(tracks[i],description_field->getText());
      changed=true;
      }

    if (tagbox->getText()!=info.tag && !tagbox->getText().empty()){
      for (FXint i=0;i<tracks.no();i++)
        db->setStreamGenre(tracks[i],tagbox->getText());
      changed=true;
      }

    if (changed) GMPlayerManager::instance()->getTrackView()->refresh();

    }
  return 1;
  }
Exemple #13
0
FXival MemoryBuffer::peek(void * b, FXival nbytes) {
  nbytes=FXMIN(size(),nbytes);
  memcpy(b,rdptr,nbytes);
  return nbytes;
  }