Commit 60649b0c authored by Scott Wheeler's avatar Scott Wheeler

more API cleanups and removed two unused files

svn path=/trunk/kdemultimedia/juk/; revision=206641
parent f68eb0df
......@@ -3,7 +3,7 @@ bin_PROGRAMS = juk
## INCLUDES were found outside kdevelop specific part
juk_SOURCES = gstreamerplayer.cpp artsplayer.cpp directorylist.cpp directorylistbase.ui stringhash.cpp sortedstringlist.cpp systemtray.cpp genrelisteditor.cpp genrelisteditorbase.ui splashscreen.cpp statuslabel.cpp cachedtag.cpp oggtag.cpp id3tag.cpp collectionlist.cpp playlistitem.cpp playlist.cpp playlistsplitter.cpp listboxpixmap.cpp playlistbox.cpp tageditor.cpp cache.cpp audiodata.cpp genrelistreader.cpp genrelistlist.cpp genrelist.cpp genre.cpp player.cpp tag.cpp customaction.cpp slideraction.cpp juk.cpp main.cpp
juk_SOURCES = gstreamerplayer.cpp artsplayer.cpp directorylist.cpp directorylistbase.ui stringhash.cpp sortedstringlist.cpp systemtray.cpp genrelisteditor.cpp genrelisteditorbase.ui splashscreen.cpp statuslabel.cpp cachedtag.cpp oggtag.cpp id3tag.cpp collectionlist.cpp playlistitem.cpp playlist.cpp playlistsplitter.cpp listboxpixmap.cpp playlistbox.cpp tageditor.cpp cache.cpp genrelistreader.cpp genrelistlist.cpp genrelist.cpp genre.cpp player.cpp tag.cpp customaction.cpp slideraction.cpp juk.cpp main.cpp
if link_lib_GST
......@@ -16,7 +16,7 @@ juk_LDADD = $(gstlibs) -lid3 -lsoundserver_idl $(LIB_KFILE) $(LIB_KDEUI) $(LIB
SUBDIRS = pics data
EXTRA_DIST = main.cpp juk.cpp juk.h juk.desktop jukui.rc slideraction.cpp slideraction.h customaction.h customaction.cpp tag.cpp tag.h player.cpp player.h genre.h genre.cpp hi16-app-juk.png hi32-app-juk.png hi48-app-juk.png genrelist.cpp genrelist.h genrelistlist.cpp genrelistlist.h genrelistreader.cpp genrelistreader.h audiodata.cpp audiodata.h cache.cpp cache.h tageditor.cpp tageditor.h playlistbox.cpp playlistbox.h listboxpixmap.cpp listboxpixmap.h playlistsplitter.cpp playlistsplitter.h playlist.cpp playlist.h playlistitem.cpp playlistitem.h collectionlist.cpp collectionlist.h id3tag.cpp id3tag.h oggtag.cpp oggtag.h cachedtag.cpp cachedtag.h statuslabel.cpp statuslabel.h splashscreen.cpp splashscreen.h genrelisteditorbase.ui genrelisteditor.cpp genrelisteditor.h systemtray.h systemtray.cpp sortedstringlist.cpp sortedstringlist.h stringhash.cpp stringhash.h directorylistbase.ui directorylist.cpp directorylist.h artsplayer.cpp artsplayer.h gstreamerplayer.cpp gstreamerplayer.h
EXTRA_DIST = main.cpp juk.cpp juk.h juk.desktop jukui.rc slideraction.cpp slideraction.h customaction.h customaction.cpp tag.cpp tag.h player.cpp player.h genre.h genre.cpp hi16-app-juk.png hi32-app-juk.png hi48-app-juk.png genrelist.cpp genrelist.h genrelistlist.cpp genrelistlist.h genrelistreader.cpp genrelistreader.h cache.cpp cache.h tageditor.cpp tageditor.h playlistbox.cpp playlistbox.h listboxpixmap.cpp listboxpixmap.h playlistsplitter.cpp playlistsplitter.h playlist.cpp playlist.h playlistitem.cpp playlistitem.h collectionlist.cpp collectionlist.h id3tag.cpp id3tag.h oggtag.cpp oggtag.h cachedtag.cpp cachedtag.h statuslabel.cpp statuslabel.h splashscreen.cpp splashscreen.h genrelisteditorbase.ui genrelisteditor.cpp genrelisteditor.h systemtray.h systemtray.cpp sortedstringlist.cpp sortedstringlist.h stringhash.cpp stringhash.h directorylistbase.ui directorylist.cpp directorylist.h artsplayer.cpp artsplayer.h gstreamerplayer.cpp gstreamerplayer.h
install-data-local:
$(mkinstalldirs) $(kde_appsdir)/Multimedia/
......
/***************************************************************************
AudioData.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
(wheeler@kde.org) 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 "audiodata.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"};
AudioData::AudioData(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;
}
}
AudioData::~AudioData()
{
free(fileglob);
}
bool AudioData::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 AudioData::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 AudioData::getBitrate() const
{
return (bitrates[version][layer - 1][bitrate_index]);
}
int AudioData::getSamplerate() const
{
return (s_freq[version][sampling_frequency]);
}
QString AudioData::getMpegver() const
{
return (version_names[version]);
}
int AudioData::getLayer() const
{
return layer;
}
QString AudioData::getMode(int mode)
{
if ((mode >= 0) && (mode < 5))
return (mode_names[mode]);
return "Stereo";
}
int AudioData::getMode() const
{
return mode;
}
int AudioData::getLength() const
{
return length;
}
QString AudioData::getLengthChar() const
{
if(success) {
int min, sec;
char buf[6];
min=length/60;
sec=length%60;
sprintf (buf, "%d:%02d", min, sec);
return buf;
}
else
return 0;
}
int AudioData::getSize() const
{
return filelen;
}
bool AudioData::getResult() const
{
return success;
}
/***************************************************************************
AudioData.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
(wheeler@kde.org) 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 AUDIODATA_H
#define AUDIODATA_H
#include <qstring.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
// I've started hacking a little on this file; both the API and the
// implementation. There's still a lot of ugly, non-Qt-happy stuff
// in here, but that will be fixed, well, as I feel motivated.
// (And fortunately I can blame someone else for this file. ;-) )
class AudioData
{
public:
AudioData(const char* filein);
virtual ~AudioData();
int getBitrate() const;
int getSamplerate() const;
QString getMpegver() const;
int getLayer() const;
static QString getMode(int mode);
int getMode() const;
int getLength() const;
QString getLengthChar() const;
int getSize() const;
bool getResult() const;
private:
bool success;
char* fileglob;
int length;
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
......@@ -22,7 +22,7 @@
// public members
////////////////////////////////////////////////////////////////////////////////
CachedTag::CachedTag(const QString &file) : Tag(file), externalTag(0), tagYear(0), tagTrackNumber(0), tagSeconds(0), tagExists(false)
CachedTag::CachedTag(const QString &file) : Tag(file), externalTag(0), tagTrackNumber(0), tagYear(0), tagSeconds(0), tagExists(false)
{
}
......
......@@ -40,11 +40,13 @@ public:
* PlaylistSplitter::createPlaylist().
*/
Playlist(PlaylistSplitter *s, QWidget *parent, const QString &name = QString::null);
/**
* Before creating a playlist directly, please see
* PlaylistSplitter::openPlaylist().
*/
Playlist(PlaylistSplitter *s, const QFileInfo &playlistFile, QWidget *parent, const char *name = 0);
virtual ~Playlist();
/**
......@@ -61,10 +63,12 @@ public:
/**
* All of the (media) files in the list.
*/
QStringList files() const;
/**
* Returns a list of all of the items in the playlist.
*/
PlaylistItemList items() const;
/**
......
......@@ -41,12 +41,32 @@ Tag *PlaylistItem::tag() const
return(data->tag());
}
// QFileInfo-ish methods
QString PlaylistItem::fileName() const { return(data->fileName()); }
QString PlaylistItem::filePath() const { return(data->filePath()); }
QString PlaylistItem::absFilePath() const { return(data->absFilePath()); }
QString PlaylistItem::dirPath(bool absPath) const { return(data->dirPath(absPath)); }
bool PlaylistItem::isWritable() const { return(data->isWritable()); }
// some forwarding methods
QString PlaylistItem::fileName() const
{
return(data->fileName());
}
QString PlaylistItem::filePath() const
{
return(data->filePath());
}
QString PlaylistItem::absFilePath() const
{
return(data->absFilePath());
}
QString PlaylistItem::dirPath(bool absPath) const
{
return(data->dirPath(absPath));
}
bool PlaylistItem::isWritable() const
{
return(data->isWritable());
}
////////////////////////////////////////////////////////////////////////////////
// PlaylistItem public slots
......
......@@ -24,7 +24,6 @@
#include <qobject.h>
#include "tag.h"
#include "audiodata.h"
#include "cache.h"
class Playlist;
......@@ -52,6 +51,7 @@ public:
// These are just forwarding methods to PlaylistItem::Data, a QFileInfo
// subclass.
QString fileName() const;
QString filePath() const;
QString absFilePath() const;
......
......@@ -167,6 +167,38 @@ QString PlaylistSplitter::playFirstFile()
return(QString::null);
}
void PlaylistSplitter::stop()
{
if(playingItem) {
playingItem->setPixmap(0, 0);
playingItem = 0;
}
}
QString PlaylistSplitter::playingArtist() const
{
if(playingItem)
return(playingItem->text(PlaylistItem::ArtistColumn));
else
return(QString::null);
}
QString PlaylistSplitter::playingTrack() const
{
if(playingItem)
return(playingItem->text(PlaylistItem::TrackColumn));
else
return(QString::null);
}
QString PlaylistSplitter::playingList() const
{
if(playingItem)
return(static_cast<Playlist *>(playingItem->listView())->name());
else
return(QString::null);
}
void PlaylistSplitter::add(const QString &file, Playlist *list)
{
KApplication::setOverrideCursor(Qt::waitCursor);
......@@ -205,46 +237,6 @@ QString PlaylistSplitter::extensionsString(const QStringList &extensions, const
return(s);
}
/*
void PlaylistSplitter::setSelected(PlaylistItem *i) // static
{
// Hu hu! See how much crap I can pack into just one pointer to a
// PlaylistItem! Sensitive viewers may want to close their eyes for the
// next few lines.
if(i) {
// Get the playlist associated with the playing item and make set the
// playing item to be both selected and visible.
Playlist *l = dynamic_cast<Playlist *>(i->listView());
if(l) {
l->clearSelection();
l->setSelected(i, true);
l->ensureItemVisible(i);
// Now move on to the PlaylistBox. The Playlist knows which
// PlaylistBoxItem that it is associated with, so we'll just get
// that and then figure out the PlaylistBox from there.
//
// Once we have that we can set the appropriate Playlist to be
// visible.
if(l->playlistBoxItem() && l->playlistBoxItem()->listBox()) {
QListBox *b = l->playlistBoxItem()->listBox();
b->clearSelection();
b->setSelected(l->playlistBoxItem(), true);
b->setCurrentItem(l->playlistBoxItem());
b->ensureCurrentVisible();
}
}
}
}
*/
////////////////////////////////////////////////////////////////////////////////
// public slots
////////////////////////////////////////////////////////////////////////////////
......@@ -301,24 +293,6 @@ Playlist *PlaylistSplitter::createPlaylist(const QString &name)
return(p);
}
void PlaylistSplitter::openPlaylist()
{
QStringList files = KFileDialog::getOpenFileNames(QString::null, "*.m3u");
for(QStringList::ConstIterator it = files.begin(); it != files.end(); ++it)
openPlaylist(*it);
}
Playlist *PlaylistSplitter::openPlaylist(const QString &playlistFile)
{
QFileInfo file(playlistFile);
if(!file.exists() || !file.isFile() || !file.isReadable() || playlistFiles.insert(file.absFilePath()))
return(0);
Playlist *p = new Playlist(this, playlistFile, playlistStack, file.baseName(true).latin1());
setupPlaylist(p);
return(p);
}
void PlaylistSplitter::selectPlaying()
{
......@@ -352,39 +326,6 @@ void PlaylistSplitter::selectPlaying()
}
}
QString PlaylistSplitter::playingArtist() const
{
if(playingItem)
return(playingItem->text(PlaylistItem::ArtistColumn));
else
return(QString::null);
}
QString PlaylistSplitter::playingTrack() const
{
if(playingItem)
return(playingItem->text(PlaylistItem::TrackColumn));
else
return(QString::null);
}
QString PlaylistSplitter::playingList() const
{
if(playingItem)
return(static_cast<Playlist *>(playingItem->listView())->name());
else
return(QString::null);
}
void PlaylistSplitter::stop()
{
if(playingItem) {
playingItem->setPixmap(0, 0);
playingItem = 0;
}
}
void PlaylistSplitter::removeSelectedItems()
{
PlaylistItemList items = playlistSelection();
......@@ -545,6 +486,17 @@ void PlaylistSplitter::setupPlaylist(Playlist *p, bool raise, const char *icon)
}
}
Playlist *PlaylistSplitter::openPlaylist(const QString &file)
{
QFileInfo fileInfo(file);
if(!fileInfo.exists() || !fileInfo.isFile() || !fileInfo.isReadable() || playlistFiles.insert(fileInfo.absFilePath()))
return(0);
Playlist *p = new Playlist(this, file, playlistStack, fileInfo.baseName(true).latin1());
setupPlaylist(p);
return(p);
}
////////////////////////////////////////////////////////////////////////////////
// private slots
////////////////////////////////////////////////////////////////////////////////
......
......@@ -63,6 +63,10 @@ public:
*/
QString uniquePlaylistName() { return(uniquePlaylistName(i18n("Playlist"))); }
////////////////////////////////////////////////////////////////////////////
// Variations on the theme "play stuff"
////////////////////////////////////////////////////////////////////////////
/**
* Returns the file name of the next item to be played and advances the next
* file.
......@@ -87,6 +91,18 @@ public:
*/
QString playFirstFile();
/**
* Since the player is handled at a higher level, this just clears the
* pointer to the currently playing item and updates the icon.
*/
void stop();
////////////////////////////////////////////////////////////////////////////
QString playingArtist() const;
QString playingTrack() const;
QString playingList() const;
/**
* Returns a list of the extensions that are used for playlists.
*/
......@@ -117,6 +133,18 @@ public:
*/
bool collectionListSelected() const { return(visiblePlaylist() == CollectionList::instance()); }
/**
* Open each of \a files, where \a files is a list of playlists and music
* files.
*/
void open(const QStringList &files) { add(files, visiblePlaylist()); }
/**
* Open \a file where \a is a playlist or music file.
*/
void open(const QString &file) { add(file, visiblePlaylist()); }
// static methods
/**
......@@ -141,16 +169,7 @@ public slots:
*/
void openDirectory();
/**
* Open each of \a files, where \a files is a list of playlists and music
* files.
*/
void open(const QStringList &files) { add(files, visiblePlaylist()); }
/**
* Open \a file where \a is a playlist or music file.
*/
void open(const QString &file) { add(file, visiblePlaylist()); }
// Tagger slots
/**
* Save.
......@@ -175,34 +194,14 @@ public slots:
*/
Playlist *createPlaylist(const QString &name);
/**
* Prompt the user for a playlist to open.
*/
void openPlaylist();
/**
* Open the playlist (m3u file or simiar) at \a playlistFile.
*/
Playlist *openPlaylist(const QString &playlistFile);