⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 veejamp.cpp

📁 Yet another mp3 player, but this time using SVGALib under Linux. The idea was to use a 320x240 disp
💻 CPP
字号:
#define VEEJAMP_VERSION "0.2"/*  VEEJAMP V0.2 (VGA MP3 player).  This program is free software; you can redistribute it and/or modify it  under the terms of the GNU General Public License as published by the  Free Software Foundation; either version 2 of the License, or (at your  option) any later version.  This program is distributed in the hope that it will be useful, but  WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  General Public License for more details, www.gnu.org.  Copyright (C) 2000  Simon Harrison (email smh@N_O_S_P_A_M@dr.com)*/#include <dirent.h>#include <unistd.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <sys/mman.h>#include <sys/types.h>#include <sys/stat.h>#include <pthread.h>#include <errno.h>#include "dirb.h"#include "font5x7.h"#include "mpgcontrol.h"#include "playlist.h"#include "svgawrap.h"#include "playlistb.h"#include "objview.h"#include "dirview.h"#include "synvis.h"//#include "playlistview.h"class CPlaylistView : public CObjectView {   int PAGE_MAX;    // Size of the directory page;   CPlaylistBrowser g_pl;   // reference to the global playlist.   public:   CPlaylistView( vgaw* d, CPlayList* pl ): PAGE_MAX(10) {      PAGE_TOP = 40;      PAGE_LEFT = 160;      g_pl.start_processing( pl );      g_pl.ScrollOn( 18, true,6 );  // some nice effects      vga = d;   // remember where the device object is.   }   ~CPlaylistView() {}   int ProcessMessages();  // Check for keyboard input    Paint();          // Update the display for this view.};CPlaylistView::Paint( ){g_pl.start_processing(NULL);char* p_select;int n = g_pl.GetPageEnts();int s = g_pl.GetSelected();CString* pde = g_pl.GetPage();int c;char buffer[1024];char* p;int l;int xofs;   if (!n) {      // nothing to do! no playlist.      hasfocus = false;      return 0;   }   if (!pde) {      printf( "Error:  Zero length list.\n" );      return 0;   }      /* page zero-based */   for (int i=0;i<n;i++) {      if ((i==s) && hasfocus) {         vga->FontHigh();            p_select = g_pl.GetScrolledSelected( &xofs );         if (p_select)            sprintf( buffer, "  %s", p_select );         else  // no scroll.            sprintf( buffer, "  %s", pde->GetName() );      } else {         vga->FontNormal();         sprintf( buffer, "  %s", pde->GetName() );      }      if ((!((i==s) && (hasfocus))) || (!p_select)) {  // normal write          // display the rightmost 20 chars, 'cos they're more useful.         l = strlen(buffer);         if (l>20) {            p = buffer;            p += (l-20);         } else {            p = buffer;         }         writexy( 10, 10*i, p );      } else {  // clip and scroll.          if (strlen(buffer)>21) buffer[21] = 0;         writexy( 4+xofs, 10*i, buffer );      }      pde++;   }   vga->FontNormal();}int CPlaylistView::ProcessMessages()// Check for key input.// If unrecognised return the key for further processing, // otherwise perform action.{int k=0;     if (!hasfocus) return 0;     k = vga->getkey();     if (k=='d') {        k=0; g_pl.del();         // delete track.     } else if (k==vga->KCurUp) {        k=0; g_pl.up();     } else if (k==vga->KCurDown) {        k=0; g_pl.down();     } else if (k==vga->KPgUp) {        k=0; g_pl.uplots();     } else if (k==vga->KPgDn) {        k=0; g_pl.downlots();     } else {        // unhandled key     }     return k;}void* visthreadf( void* )//// This fakes program arguments, so I don't change synaesthia too much.// Could be neater!  TODO:  Get the sampling rate from the mp3 header// so we can play lower quality mp3s.//{//const char* a="pipe";//const char* b="44100";char* args[4];   args[0] = "mygl";   args[1] = "pipe";   args[2] = "44100";   args[3] = NULL;   VisualisationThread( 3, args );   // never returns.   return NULL;}CPlayList g_playlist;     // the playlist itself (must be global).vgaw* display;CDirView* cdv;            // directory browser viewCPlaylistView* plview;    // playlist browser viewmpgreturn mpgr;bool hud_on=true;int main(void){int x=0;int y=0;int i;int k=0;char buffer2[1024];char* p;int ok=1;CString* cde;char* fi=NULL;char now_playing[1024];   printf( "VEEJAMP V%s\n", VEEJAMP_VERSION );   // make the fifo.  This'll fail if it doesn't exist   // NB: Still single threaded, so using errno is OK.   if (-1==mkfifo( FIFO_NAME, S_IRUSR | S_IWUSR )) {      if (errno!=EEXIST) {         printf( "Error creating fifo %s\n", FIFO_NAME );         exit(1);        }   }   pthread_t visthread;   // kick off a thread for the visualisation.   pthread_create( &visthread, NULL, visthreadf, NULL );   // Open access to the display object.  hint: only one of these gets   // created for svgalib :-)   display = new vgaw;   // Kick off a directory browser, with access to the display and playlist.   cdv = new CDirView(display, &g_playlist );   plview = new CPlaylistView( display, &g_playlist );                                           // a browser object to view it.   plview->SetFocus(false);   cdv->SetFocus(true);   // dir browser starts with focus.   // start mpg123.   mpgcontroller::startthread();      // draw the first directory screen.   cdv->Paint();   while(ok) {      if (hud_on) {        if (!plview->GetFocus())           cdv->SetFocus(true);        k = cdv->ProcessMessages();   // All keys default to the dir browser                                   // k!=0 means rejected key input.     } else {        k = display->getkey();     }     if (!k)             k = plview->ProcessMessages();     if (k=='p') {            // ...so try other stuff.        mpgcontroller::pause();     } else if (k=='f') {        mpgcontroller::jump( +100 );     } else if (k=='b') {        mpgcontroller::jump( -100 );     } else if (k=='1') {        SetVisualisationFP( 1 );     } else if (k=='2') {        SetVisualisationFP( 2 );     } else if (k=='3') {        SetVisualisationFP( 3 );     } else if (k==' ') {  // visualisation only.        if (hud_on) hud_on = false;               else hud_on = true;     } else if (k=='n') {  // next track.        // mpgcontroller::quit();        if (g_playlist.GetHead()) {           mpgcontroller::load( g_playlist.GetHead() );           g_playlist.ChopHead();        }     } else if (k=='t') {        plview->SetFocus(true);        cdv->SetFocus(false);     } else if (k=='r') {        plview->SetFocus(false);        cdv->SetFocus(true);     } else {    // ... or give up.       if (k=='q') ok = 0;     }      k = 0;     display->updatevis();   // update the visualisation.     if (mpgcontroller::get_safe_data( &mpgr, now_playing )) {        char buffer[1024];        if (hud_on)           display->spaced_gl_write( 10,10,mpgcontroller::format_playinfo(&mpgr) );        sprintf( buffer, "Playing: %s ", now_playing );        int l = strlen( buffer);        char* p;        if (l>50) {           p = buffer;           p+= (l-50);        } else {           p = buffer;        }        if (hud_on) display->spaced_gl_write( 10,00,p);     } else {        // check for new material in playlist.        if (g_playlist.GetHead()) {           mpgcontroller::load( g_playlist.GetHead() );           g_playlist.ChopHead();        }     }     if (hud_on) {        cdv->Paint();        plview->Paint();     }     display->updatereal();     usleep( 10000 );   }   delete display;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -