This is just my work that never got comitted due to freeamp moving
around and what not along with some late tweaks. This patch does the
following against the latest CVS of freeamp. All are linux oriented
where outside of /base... this will change later.
- fixes up lastDir option
- software volume mixer for OSS (freeamp wont touch your hardware mixer)
- attempts to fix problems starting freeamp without a playlist
software volume is the biggy here. 100% in freeamp is whatever your
hardware mixer controls have set PCM volume to. freeamp defaults to 0
so no accidental overload is made. Now the option to allow multiple
freeamp's to be run actually makes sense.
Lastdir fixes are to finalize it's entry as a real option and will save
the position of the "add items" menu to the position of the last file
that was added across freeamp sessions.
the loading fixes are attempts to fix locks and segfaults caused by
loading freeamp with no items in a playlist, no playlist present while
not having a file argument. It was my experience to see freeamp lock or
freeze in such situations but with the following patch it no longer
does.
also as a final note, perhaps due to fixes in gtk or maybe i was crazy,
but the "add item" menu no longer adds a highlighted directory like it
would a file to the playlist, you must enter the top level dir you wish
to add files from (be that a directory full of directories of files or a
directory full of files) and press ok. No highlighting of files or
directories is needed when doing a recursive addition of files.
If you wish to only add certain files, selected them and press ok. not
selecting files and pressing ok will result in a recursive selection of
all files under the current dir.
diff -Naur -x CVS -x corba -x *.log -x *.orig -x *.rej ../clean/freeamp/base/include/preferences.h ./freeamp/base/include/preferences.h
--- ../clean/freeamp/base/include/preferences.h Tue Apr 16 13:14:28 2002
+++ ./freeamp/base/include/preferences.h Sun Jun 23 02:49:52 2002
@@ -82,6 +82,7 @@
extern const char* kWelcomePref;
extern const char* kPlayImmediatelyPref;
extern const char* kSetLastResumePref;
+extern const char* kLastDirPref;
extern const char* kNumberOfURLsToRememberPref;
extern const char* kCDDevicePathPref;
extern const char* kCheckCDAutomaticallyPref;
diff -Naur -x CVS -x corba -x *.log -x *.orig -x *.rej ../clean/freeamp/base/src/player.cpp ./freeamp/base/src/player.cpp
--- ../clean/freeamp/base/src/player.cpp Wed May 23 19:45:50 2001
+++ ./freeamp/base/src/player.cpp Sun Jun 23 02:49:52 2002
@@ -74,6 +74,7 @@
const char *szPlaylistExt = ".M3U";
const char *themeExtension = "fat";
+char old_path[PATH_MAX];
#define SEND_NORMAL_EVENT(e) { Event *ev = new Event(e); GetUIManipLock(); \
SendToUI(ev); ReleaseUIManipLock(); delete ev; \
}
@@ -463,12 +464,10 @@
HandleSingleArg(arg);
}
}
-
- if(m_autoplay)
- {
- AcceptEvent(new Event(CMD_Play));
- }
-
+ bool bPlay;
+ m_context->prefs->GetPrefBoolean(kPlayImmediatelyPref, &bPlay);
+ if(bPlay)
+ AcceptEvent(new Event(CMD_Play));
return true;
}
diff -Naur -x CVS -x corba -x *.log -x *.orig -x *.rej ../clean/freeamp/base/src/playlist.cpp ./freeamp/base/src/playlist.cpp
--- ../clean/freeamp/base/src/playlist.cpp Mon Dec 17 00:13:15 2001
+++ ./freeamp/base/src/playlist.cpp Sun Jun 23 03:35:40 2002
@@ -2347,8 +2347,8 @@
uint32 size = 0;
assert(list);
- assert(item);
-
+ if(item)
+ assert(item);
if(list && item)
{
vector<PlaylistItem*>::iterator i = list->begin();
diff -Naur -x CVS -x corba -x *.log -x *.orig -x *.rej ../clean/freeamp/base/src/preferences.cpp ./freeamp/base/src/preferences.cpp
--- ../clean/freeamp/base/src/preferences.cpp Tue Apr 16 13:14:28 2002
+++ ./freeamp/base/src/preferences.cpp Sun Jun 23 02:49:52 2002
@@ -80,6 +80,7 @@
const char* kWelcomePref = "Welcome";
const char* kPlayImmediatelyPref = "PlayImmediately";
const char* kSetLastResumePref = "SetLastResume";
+const char* kLastDirPref = "LastDir";
const char* kNumberOfURLsToRememberPref = "NumberOfURLsToRemember";
const char* kCDDevicePathPref = "CDDevice";
const char* kCheckCDAutomaticallyPref = "AutoUpdateCD";
@@ -126,7 +127,7 @@
const bool kDefaultUseNIC = false;
const char *kDefaultNICAddress = "192.168.1.1";
const bool kDefaultUseTitleStreaming = true;
-const char *kDefaultThemePath = "";
+const char *kDefaultThemePath = "~/.freeamp/themes/FreeAmp.fat";
const char *kDefaultMainWindowPos = "-1,-1";
const char *kDefaultWindowMode = "MainWindow";
#ifdef WIN32
@@ -158,6 +159,7 @@
const bool kDefaultWelcome = true;
const bool kDefaultPlayImmediately = true;
const bool kDefaultSetLastResume = true;
+const char* kDefaultLastDir = "/";
const int32 kDefaultNumberOfURLsToRemember = 10;
const char* kDefaultMBServer = "http://www.musicbrainz.org:80";
const bool kDefaultConvertUnderscoresToSpaces = true;
@@ -351,7 +353,12 @@
if (GetPrefBoolean(kSetLastResumePref, &dummyBool) == kError_NoPrefValue)
SetPrefBoolean(kSetLastResumePref, kDefaultSetLastResume);
-
+
+ dummyInt = 255;
+ if (GetPrefString(kLastDirPref, dummyString,
+ (uint32 *)&dummyInt) == kError_NoPrefValue)
+ SetPrefString(kLastDirPref, kDefaultLastDir);
+
if (GetPrefInt32(kNumberOfURLsToRememberPref, &dummyInt) == kError_NoPrefValue)
SetPrefInt32(kNumberOfURLsToRememberPref, kDefaultNumberOfURLsToRemember);
diff -Naur -x CVS -x corba -x *.log -x *.orig -x *.rej ../clean/freeamp/base/unix/src/bootstrap.cpp ./freeamp/base/unix/src/bootstrap.cpp
--- ../clean/freeamp/base/unix/src/bootstrap.cpp Tue Apr 16 13:14:28 2002
+++ ./freeamp/base/unix/src/bootstrap.cpp Sun Jun 23 02:49:52 2002
@@ -244,8 +244,6 @@
{
pP->SetTerminationSemaphore(termSemaphore);
pP->Run();
- if(!bPlay)
- context->target->AcceptEvent(new Event(CMD_Stop));
for(;;)
{
if (!termSemaphore->TimedWait(1000))
diff -Naur -x CVS -x corba -x *.log -x *.orig -x *.rej ../clean/freeamp/io/soundcard/unix/linux/include/soundcardpmo.h ./freeamp/io/soundcard/unix/linux/include/soundcardpmo.h
--- ../clean/freeamp/io/soundcard/unix/linux/include/soundcardpmo.h Thu May 4 06:54:57 2000
+++ ./freeamp/io/soundcard/unix/linux/include/soundcardpmo.h Sun Jun 23 03:13:57 2002
@@ -38,6 +38,8 @@
#define SLEEPTIME 256
static const uint32 OBUFFERSIZE = 2 * 1152;
+int Right=0;
+int Left=0;
enum
{
diff -Naur -x CVS -x corba -x *.log -x *.orig -x *.rej ../clean/freeamp/io/soundcard/unix/linux/src/soundcardpmo.cpp ./freeamp/io/soundcard/unix/linux/src/soundcardpmo.cpp
--- ../clean/freeamp/io/soundcard/unix/linux/src/soundcardpmo.cpp Sun Jan 28 01:52:05 2001
+++ ./freeamp/io/soundcard/unix/linux/src/soundcardpmo.cpp Sun Jun 23 03:16:15 2002
@@ -99,29 +99,21 @@
}
}
+// Software Volume control blatently stolen from AlsaPlayer
+// Thank you Andy Lo A Foe
void SoundCardPMO::SetVolume(int32 left, int32 right)
{
- int mixFd = open("/dev/mixer",O_RDWR);
- int32 v;
- if (mixFd != -1)
- {
- v = (right << 8) | left;
- ioctl(mixFd, SOUND_MIXER_WRITE_PCM, &v);
- close(mixFd);
- }
+ static int vol_scale[] = {0,1,2,4,7,12,18,26,35,45,56,69,75,87,100 };
+ Right = vol_scale[(int)(14*((double)right/100))];
+ Left = vol_scale[(int)(14*((double)left/100))];
}
void SoundCardPMO::GetVolume(int32 &left, int32 &right)
{
- int mixFd = open("/dev/mixer",O_RDWR);
- int volume = 0;
- if (mixFd != -1)
- {
- ioctl(mixFd, SOUND_MIXER_READ_PCM, &volume);
- close(mixFd);
+ if(Left == 0 && Right == 0){
+ left = Left;
+ right = Right;
}
- right = (volume >> 8) & 0xFF;
- left = volume & 0xFF;
}
int SoundCardPMO::audio_fd = -1;
@@ -503,7 +495,16 @@
m_pInputBuffer->EndRead(0);
continue;
}
-
+ // Takes audio data and changes the level of it before
+ // being written to the audio device. (alsaplayer's)
+ short *data = (short *)pBuffer;
+ if(Right == -1) Right = Left;
+ for (int i=0; i < m_iDataSize << 1; i+=8) {
+ int v=(int) ((*(data) * Left) / 100);
+ *(data++)=(v>32767) ? 32767 : ((v<-32768) ? -32768 : v);
+ v=(int) ((*(data) * Right) / 100);
+ *(data++)=(v>32767) ? 32767 : ((v<-32768) ? -32768 : v);
+ }
iRet = write(audio_fd, pBuffer, m_iDataSize);
if ((int)iRet < 0)
{
@@ -513,7 +514,7 @@
strerror(errno));
break;
}
-
+
m_iTotalBytesWritten += iRet;
m_pInputBuffer->EndRead(iRet);
m_pLmc->Wake();
diff -Naur -x CVS -x corba -x *.log -x *.orig -x *.rej ../clean/freeamp/ui/freeamp/src/FreeAmpTheme.cpp ./freeamp/ui/freeamp/src/FreeAmpTheme.cpp
--- ../clean/freeamp/ui/freeamp/src/FreeAmpTheme.cpp Sun Sep 9 17:51:08 2001
+++ ./freeamp/ui/freeamp/src/FreeAmpTheme.cpp Sun Jun 23 03:38:31 2002
@@ -114,7 +114,7 @@
m_iSeekSeconds = 0;
m_bSeekInProgress = false;
m_bVolumeChangeInProgress = false;
- m_iVolume = -1;
+ m_iVolume = 0;
m_iBalance = -1;
m_iSeekPos = -1;
m_iMuteVolume = -1;
diff -Naur -x CVS -x corba -x *.log -x *.orig -x *.rej ../clean/freeamp/ui/freeamp/unix/include/GTKPreferenceWindow.h ./freeamp/ui/freeamp/unix/include/GTKPreferenceWindow.h
--- ../clean/freeamp/ui/freeamp/unix/include/GTKPreferenceWindow.h Tue Apr 16 13:14:28 2002
+++ ./freeamp/ui/freeamp/unix/include/GTKPreferenceWindow.h Sun Jun 23 02:49:52 2002
@@ -78,6 +78,7 @@
bool savePlaylistOnExit;
bool playImmediately;
bool setLastResume;
+ string LastDir;
bool allowMultipleInstances;
string saveMusicDirectory;
@@ -109,6 +110,7 @@
allowMultipleInstances == pref.allowMultipleInstances &&
playImmediately == pref.playImmediately &&
setLastResume == pref.setLastResume &&
+ LastDir == pref.LastDir &&
useTextLabels == pref.useTextLabels &&
useImages == pref.useImages &&
savePlaylistOnExit == pref.savePlaylistOnExit &&
diff -Naur -x CVS -x corba -x *.log -x *.orig -x *.rej ../clean/freeamp/ui/freeamp/unix/src/GTKFileSelector.cpp ./freeamp/ui/freeamp/unix/src/GTKFileSelector.cpp
--- ../clean/freeamp/ui/freeamp/unix/src/GTKFileSelector.cpp Tue Apr 16 13:14:28 2002
+++ ./freeamp/ui/freeamp/unix/src/GTKFileSelector.cpp Sun Jun 23 02:49:52 2002
@@ -25,11 +25,13 @@
#include <unistd.h>
#include <dirent.h>
-char old_path[PATH_MAX];
+
+extern char old_path[PATH_MAX];
+
GTKFileSelector::GTKFileSelector(FAContext *context,const char *windowtitle)
{
- m_context = context;
+ m_context = context;
title = windowtitle;
returnpath = "";
extended = false;
@@ -101,10 +103,11 @@
returnpath = gtk_file_selection_get_filename(gfile);
path_temp = strdup(returnpath.c_str());
-
+ if(path_temp[strlen(path_temp)-1]=='/')
+ row=NULL;
char *tempdir = strrchr(path_temp, '/');
if (!tempdir) {
- strcpy(path_temp, "./");
+ strcpy(path_temp, "/");
path_temp = (char *)realloc(path_temp, strlen(path_temp) + 1);
}
else
@@ -143,18 +146,25 @@
ok = true;
done = true;
+ m_context->prefs->SetPrefString(kLastDirPref,old_path);
}
bool GTKFileSelector::Run(bool runMain)
{
- bool dummyBool;
+ bool dummyBool;
+ int32 dummyInt;
if (!runMain)
gdk_threads_enter();
filesel = gtk_file_selection_new(title.c_str());
m_context->prefs->GetPrefBoolean(kSetLastResumePref, &dummyBool);
- if(dummyBool)
- gtk_file_selection_set_filename (GTK_FILE_SELECTION (filesel), old_path);
+ dummyInt = PATH_MAX;
+ if(dummyBool){
+ m_context->prefs->GetPrefString(kLastDirPref,old_path,(uint32 *)&dummyInt);
+ gtk_file_selection_set_filename (GTK_FILE_SELECTION (filesel), old_path);
+ }
+ else
+ m_context->prefs->SetPrefString(kLastDirPref,"/");
gtk_window_set_modal(GTK_WINDOW(filesel), TRUE);
gtk_signal_connect(GTK_OBJECT(filesel), "destroy",
GTK_SIGNAL_FUNC(filesel_destroy), (gpointer)runMain);
diff -Naur -x CVS -x corba -x *.log -x *.orig -x *.rej ../clean/freeamp/ui/freeamp/unix/src/GTKPreferenceWindow.cpp ./freeamp/ui/freeamp/unix/src/GTKPreferenceWindow.cpp
--- ../clean/freeamp/ui/freeamp/unix/src/GTKPreferenceWindow.cpp Tue Apr 16 13:14:28 2002
+++ ./freeamp/ui/freeamp/unix/src/GTKPreferenceWindow.cpp Sun Jun 23 02:49:52 2002
@@ -37,6 +37,8 @@
#include "MessageDialog.h"
#include "help.h"
+extern char old_path[PATH_MAX];
+
GTKPreferenceWindow::GTKPreferenceWindow(FAContext *context,
ThemeManager *pThemeMan,
uint32 defaultPage) :
@@ -449,7 +451,16 @@
prefs->GetPrefBoolean(kPlayImmediatelyPref, &values->playImmediately);
prefs->GetPrefBoolean(kSetLastResumePref, &values->setLastResume);
-
+ values->saveMusicDirectory = buffer;
+ size = bufferSize;
+
+ if(kError_BufferTooSmall == prefs->GetPrefString(kLastDirPref, buffer, &size))
+ {
+ bufferSize = size;
+ buffer = (char*)realloc(buffer, bufferSize);
+ prefs->GetPrefString(kLastDirPref, buffer, &size);
+ }
+
prefs->GetPrefBoolean(kAllowMultipleInstancesPref, &values->allowMultipleInstances);
if(kError_BufferTooSmall == prefs->GetPrefString(kSaveMusicDirPref, buffer, &size))
@@ -545,6 +556,7 @@
prefs->SetPrefBoolean(kPlayImmediatelyPref, values->playImmediately);
prefs->SetPrefBoolean(kSetLastResumePref, values->setLastResume);
+ prefs->SetPrefString(kLastDirPref,old_path);
prefs->SetPrefBoolean(kAllowMultipleInstancesPref, values->allowMultipleInstances);
prefs->SetPrefBoolean(kAskToReclaimFiletypesPref, values->askReclaimFiletypes);
diff -Naur -x CVS -x corba -x *.log -x *.orig -x *.rej ../clean/freeamp/ui/musicbrowser/unix/src/fileselector.cpp ./freeamp/ui/musicbrowser/unix/src/fileselector.cpp
--- ../clean/freeamp/ui/musicbrowser/unix/src/fileselector.cpp Tue Apr 16 13:14:28 2002
+++ ./freeamp/ui/musicbrowser/unix/src/fileselector.cpp Sun Jun 23 02:54:09 2002
@@ -34,7 +34,7 @@
#include "utility.h"
#include "preferences.h"
-char old_path[PATH_MAX]="/\0";
+extern char old_path[PATH_MAX];
FileSelector::FileSelector(FAContext *context,const char *windowtitle)
{
@@ -115,21 +115,23 @@
gtk_widget_destroy(GTK_WIDGET(gfile));
ok = true;
done = true;
-
return;
}
returnpath = gtk_file_selection_get_filename(gfile);
path_temp = strdup(returnpath.c_str());
raw_path = gtk_entry_get_text(GTK_ENTRY(gfile->selection_entry));
+ if(path_temp[strlen(path_temp)-1]=='/')
+ row=NULL;
char *tempdir = strrchr(path_temp, '/');
strncpy(old_path,path_temp,PATH_MAX);
if (!tempdir) {
- strcpy(path_temp, "./");
+ strcpy(path_temp, "/");
path_temp = (char *)realloc(path_temp, strlen(path_temp) + 1);
}
else
tempdir[0] = '\0';
+
if(row){
while (row) {
if (GTK_CLIST_ROW(row)->state == GTK_STATE_SELECTED) {
@@ -157,22 +159,30 @@
}
rownum += sub_rnum;
gtk_widget_destroy(GTK_WIDGET(gfile));
- free(path_temp);
+ if(path_temp)
+ free(path_temp);
ok = true;
done = true;
+ m_context->prefs->SetPrefString(kLastDirPref, old_path);
}
bool FileSelector::Run(bool runMain)
{
bool dummyBool;
+ int32 dummyInt;
if (!runMain)
gdk_threads_enter();
filesel = gtk_file_selection_new(title.c_str());
m_context->prefs->GetPrefBoolean(kSetLastResumePref, &dummyBool);
- if(dummyBool)
- gtk_file_selection_set_filename (GTK_FILE_SELECTION (filesel), old_path);
+ dummyInt = PATH_MAX;
+ if(dummyBool){
+ m_context->prefs->GetPrefString(kLastDirPref, old_path, (uint32 *)&dummyInt);
+ gtk_file_selection_set_filename (GTK_FILE_SELECTION (filesel), old_path);
+ }
+ else
+ m_context->prefs->SetPrefString(kLastDirPref,"/");
gtk_window_set_modal(GTK_WINDOW(filesel), TRUE);
gtk_signal_connect(GTK_OBJECT(filesel), "destroy",
GTK_SIGNAL_FUNC(filesel_destroy), (gpointer)runMain);