Commit f1fde603 authored by Scott Wheeler's avatar Scott Wheeler

initial import for the JuK branch -- JuK is a KDE 3 port of QTagger that

will eventually support jukebox features.  Most things still aren't
implemented.

svn path=/trunk/kdemultimedia/juk/; revision=140480
parent b18046a2
/***************************************************************************
MPEGHeader.cpp is a modified version of fileinfo.cpp which is a part of
Mp3Kult (C) 2001 by Stefano Brustia (hio@lombardiacom.it) which is
available at:
http://mp3kult.sourceforge.net/
fileinfo.cpp was modified to just include header information instead of
header and id3 information. These changes were made by Scott Wheeler
(scott@slackorama.net) on 1/13/2002 based on Mp3Kult v0.5.
***************************************************************************/
/***************************************************************************
* 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. *
***************************************************************************/
#include "MPEGHeader.h"
#include <iostream.h>
#include <ctype.h>
unsigned int bitrates[3][3][15] =
{
{
{0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448},
{0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384},
{0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320}
},
{
{0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256},
{0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160},
{0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160}
},
{
{0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256},
{0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160},
{0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160}
}};
unsigned int s_freq[3][4] =
{
{44100, 48000, 32000, 0},
{22050, 24000, 16000, 0},
{11025, 8000, 8000, 0}
};
static const char *mode_names[5] =
{"Stereo", "Joint Stereo", "Dual Ch", "Mono", "Multi Ch"};
const char *layer_names[3] =
{"I", "II", "III"};
const char *version_names[3] =
{"MPEG-1", "MPEG-2 LSF", "MPEG-2.5"};
const char *version_nums[3] =
{"1", "2", "2.5"};
MPEGHeader::MPEGHeader(const char* filein)
{
success = false;
fileglob = strdup(filein);
FILE* file;
if ((file = fopen(filein, "r")))
{
success=readLayerInfo(file);
fclose(file);
}
else // File isn't readable
{
success = false;
}
}
MPEGHeader::~MPEGHeader()
{
}
bool MPEGHeader::readLayerInfo (FILE* file)
{
unsigned char buf[4];
unsigned long head;
struct stat fi;
fstat(fileno(file), &fi);
filelen = fi.st_size;
fseek(file, 0, SEEK_SET);
if (fread(buf, 1, 4, file) != 4)
return false;
head = ((unsigned long) buf[0] << 24) | ((unsigned long) buf[1] << 16) |
((unsigned long) buf[2] << 8) | ((unsigned long) buf[3]);
while (!headCheck(head))
{
head <<= 8;
if (fread(buf, 1, 1, file) != 1)
{
return false;
}
head |= buf[0];
}
switch (((head >> 19) & 0x3) )
{
case 3:
version = 0;
break;
case 2:
version = 1;
break;
case 0:
version = 2;
break;
default:
return false;
}
layer = 4 - ((head >> 17) & 3);
error_protection = ((head >> 16) & 0x1) ^ 0x1;
bitrate_index = ((head >> 12) & 0xf);
sampling_frequency = ((head >> 10) & 0x3);
padding = ((head >> 9) & 0x1);
extension = ((head >> 8) & 0x1);
mode = ((head >> 6) & 0x3);
mode_ext = ((head >> 4) & 0x3);
copyright = ((head >> 3) & 0x1);
original = ((head >> 2) & 0x1);
emphasis = head & 0x3;
if (!bitrate_index)
return false;
length = filelen / ((getBitrate()) * 125);
return true;
}
bool MPEGHeader::headCheck(unsigned long head)
{
if ((head & 0xffe00000) != 0xffe00000)
return false;
if (!((head >> 17) & 3))
return false;
if (((head >> 12) & 0xf) == 0xf)
return false;
if (!((head >> 12) & 0xf))
return false;
if (((head >> 10) & 0x3) == 0x3)
return false;
if (((head >> 19) & 1) == 1 && ((head >> 17) & 3) == 3 &&
((head >> 16) & 1) == 1)
return false;
if ((head & 0xffff0000) == 0xfffe0000)
return false;
return true;
}
int MPEGHeader::getBitrate(){
return (bitrates[version][layer - 1][bitrate_index]);
}
int MPEGHeader::getSamplerate(){
return (s_freq[version][sampling_frequency]);
}
const char* MPEGHeader::getMpegver(){
return (version_names[version]);
}
int MPEGHeader::getLayer() {
return layer;
}
const char* MPEGHeader::getMode(int mode)
{
if ((mode >= 0) && (mode < 5))
return (mode_names[mode]);
return "Stereo";
}
int MPEGHeader::getMode()
{
return mode;
}
int MPEGHeader::getLength() {
return length;
}
char* MPEGHeader::getLengthChar() {
int min, sec;
char buf[6];
min=length/60;
sec=length%60;
/* if (sec < 10)
sprintf (buf, "%d:0%d", min, sec);
else */
sprintf (buf, "%d:%02d", min, sec);
lengthchar=strdup (buf);
return lengthchar;
}
int MPEGHeader::getSize() {
return filelen;
}
bool MPEGHeader::getResult()
{
return success;
}
/***************************************************************************
MPEGHeader.h is a modified version of fileinfo.h which is a part of
Mp3Kult (C) 2001 by Stefano Brustia (hio@lombardiacom.it) which is
available at:
http://mp3kult.sourceforge.net/
fileinfo.h was modified to just include header information instead of
header and id3 information. These changes were made by Scott Wheeler
(scott@slackorama.net) on 1/13/2002 based on Mp3Kult v0.5.
***************************************************************************/
/***************************************************************************
* 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. *
***************************************************************************/
#ifndef MPEGHEADER_H
#define MPEGHEADER_H
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
class MPEGHeader
{
public:
MPEGHeader(const char* filein);
~MPEGHeader();
int getBitrate();
int getSamplerate();
const char* getMpegver();
int getLayer();
static const char* getMode(int mode);
int getMode();
int getLength();
char* getLengthChar();
int getSize();
bool getResult();
private:
bool success;
char* fileglob;
int length;
char* lengthchar;
int version;
int filelen;
int layer;
int error_protection;
int bitrate_index;
int sampling_frequency;
int padding;
int extension;
int mode;
int mode_ext;
int copyright;
int original;
int emphasis;
bool headCheck(unsigned long head);
bool readLayerInfo(FILE* file);
};
#endif // MPEGHEADER_H
####### kdevelop will overwrite this part!!! (begin)##########
bin_PROGRAMS = juk
## INCLUDES were found outside kdevelop specific part
juk_SOURCES = genre.cpp player.cpp MPEGHeader.cpp filelistitem.cpp tag.cpp filelist.cpp customaction.cpp playlistwidget.cpp slideraction.cpp taggerwidget.cpp juk.cpp main.cpp
juk_LDADD = -lid3 -lsoundserver_idl $(LIB_KFILE) $(LIB_KDEUI) $(LIB_KDECORE) $(LIB_QT) $(LIBSOCKET)
SUBDIRS = pics
EXTRA_DIST = main.cpp juk.cpp juk.h juk.desktop jukui.rc taggerwidget.cpp taggerwidget.h slideraction.cpp slideraction.h playlistwidget.cpp playlistwidget.h customaction.h customaction.cpp filelist.cpp filelist.h tag.cpp tag.h filelistitem.cpp filelistitem.h MPEGHeader.cpp MPEGHeader.h player.cpp player.h genre.h genre.cpp hi16-app-juk.png hi32-app-juk.png hi48-app-juk.png
install-data-local:
$(mkinstalldirs) $(kde_appsdir)/Multimedia/
$(INSTALL_DATA) $(srcdir)/juk.desktop $(kde_appsdir)/Multimedia/juk.desktop
uninstall-local:
-rm -f $(kde_appsdir)/Multimedia/juk.desktop
####### kdevelop will overwrite this part!!! (end)############
# set the include path for X, qt and KDE
INCLUDES= $(all_includes) $(KDE_INCLUDES)/arts
METASOURCES = AUTO
KDE_ICON = AUTO
# the library search path.
juk_LDFLAGS = $(all_libraries) $(KDE_RPATH)
rcdir = $(kde_datadir)/juk
rc_DATA = jukui.rc
messages: rc.cpp
This diff is collapsed.
/***************************************************************************
customaction.cpp - description
-------------------
begin : Wed Feb 6 2002
copyright : (C) 2002 by Scott Wheeler
email : scott@slackorama.net
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include "customaction.h"
////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////
CustomAction::CustomAction(const QString &text, QObject *parent, const char *name)
: KAction(text, 0, parent, name)
{
toolbar=NULL;
}
CustomAction::~CustomAction()
{
}
int CustomAction::plug(QWidget *parent, int index)
{
customWidget = createWidget(parent);
if(customWidget) {
// the check for null makes sure that there is only one toolbar that this is
// "plugged" in to
if (parent->inherits("KToolBar") && !toolbar) {
toolbar = static_cast<KToolBar *>(parent);
int id = KAction::getToolButtonID();
toolbar->insertWidget(id, customWidget->width(), customWidget, index);
addContainer(toolbar, id);
connect(toolbar, SIGNAL(destroyed()), this, SLOT(slotDestroyed()));
return (containerCount() - 1);
}
return(-1);
}
else {
return(-1);
}
}
void CustomAction::unplug(QWidget *parent)
{
if (parent->inherits("KToolBar")) {
toolbar = static_cast<KToolBar *>(parent);
int index = findContainer(toolbar);
if (index != -1) {
toolbar->removeItem(itemId(index));
removeContainer(index);
toolbar=NULL;
}
}
}
////////////////////////////////////////////////////////////////////////////////
// protected members
////////////////////////////////////////////////////////////////////////////////
KToolBar *CustomAction::getToolBar()
{
return(toolbar);
}
QWidget *CustomAction::createWidget(QWidget *parent) // virtual, should be reimplemented in subclasses
{
return(0);
}
/***************************************************************************
customaction.h - description
-------------------
begin : Wed Feb 6 2002
copyright : (C) 2002 by Scott Wheeler
email : scott@slackorama.net
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#ifndef CUSTOMACTION_H
#define CUSTOMACTION_H
#include <kaction.h>
#include <ktoolbar.h>
#include <qstring.h>
#include <qobject.h>
class CustomAction : public KAction
{
Q_OBJECT
public:
CustomAction(const QString &text, QObject *parent, const char *name);
~CustomAction();
virtual int plug(QWidget *parent, int index = -1);
virtual void unplug(QWidget *widget);
protected:
KToolBar *getToolBar();
virtual QWidget *createWidget(QWidget *parent);
QWidget *customWidget;
KToolBar *toolbar;
private:
signals:
void pluggedIn(QWidget *parent);
};
#endif
/***************************************************************************
filelist.cpp - description
-------------------
begin : Sat Feb 16 2002
copyright : (C) 2002 by Scott Wheeler
email : scott@slackorama.net
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include <klocale.h>
#include <qfileinfo.h>
#include <qdir.h>
#include <qtimer.h>
#include <qapplication.h>
#include "filelist.h"
////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////
FileList::FileList(QWidget *parent = 0, const char *name = 0) : KListView(parent, name)
{
setup();
}
FileList::FileList(QString item, QWidget *parent = 0, const char *name = 0)
{
setup();
append(item);
}
FileList::FileList(QStringList *items, QWidget *parent = 0, const char *name = 0)
{
setup();
append(items);
}
FileList::~FileList()
{
}
void FileList::append(QString item)
{
QApplication::setOverrideCursor(Qt::waitCursor);
appendImpl(item);
QApplication::restoreOverrideCursor();
}
void FileList::append(QStringList *items)
{
QApplication::setOverrideCursor(Qt::waitCursor);
for(QStringList::Iterator it = items->begin(); it != items->end(); ++it) {
appendImpl(*it);
}
QApplication::restoreOverrideCursor();
}
FileListItem *FileList::getSelectedItem()
{
return(dynamic_cast<FileListItem *>(currentItem()));
}
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////
void FileList::setup()
{
extensions.append("mp3");
addColumn(i18n("Track Name"));
addColumn(i18n("Artist"));
addColumn(i18n("Album"));
addColumn(i18n("Track"));
addColumn(i18n("Genre"));
addColumn(i18n("Year"));
addColumn(i18n("File Name"));
setAllColumnsShowFocus(true);
setShowSortIndicator(true);
setItemMargin(3);
setSorting(1);
// QColor backGround = paletteBackgroundColor();
// int r, g, b;
// backGround.rgb(&r, &g, &b);
// r=r-5; g=g-5; b=b-5;
// const QColor ab(10,10,10);
// setAlternateBackground(ab);
}
void FileList::appendImpl(QString item)
{
QFileInfo *file = new QFileInfo(QDir::cleanDirPath(item));
if(file->exists()) {
if(file->isDir()) {
QDir dir(file->filePath());
QStringList dirContents=dir.entryList();
for(QStringList::Iterator it = dirContents.begin(); it != dirContents.end(); ++it) {
if(*it != "." && *it != "..") {
appendImpl(file->filePath() + QDir::separator() + *it);
}
}
}
else {
// QFileInfo::extension() doesn't always work, so I'm getting old-school on this.
QString extension=file->filePath().right(file->filePath().length() - (file->filePath().findRev(".")+1));
if(extensions.contains(extension) > 0 && members.contains(file->absFilePath()) == 0) {
members.append(file->absFilePath());
(void) new FileListItem(file, this);
}
}
}
}
/***************************************************************************
filelist.h - description
-------------------
begin : Sat Feb 16 2002
copyright : (C) 2002 by Scott Wheeler
email : scott@slackorama.net
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#ifndef FILELIST_H
#define FILELIST_H
#include <klistview.h>
#include <qstringlist.h>
#include "filelistitem.h"
class FileList : public KListView
{
public:
FileList(QWidget *parent = 0, const char *name = 0);
FileList(QString item, QWidget *parent = 0, const char *name = 0);
FileList(QStringList *items, QWidget *parent = 0, const char *name = 0);
~FileList();
void append(QString item);
void append(QStringList *items);
FileListItem *getSelectedItem();
private:
void setup();
void appendImpl(QString item);
QStringList extensions;
QStringList members;