/** Main program entry point. This routine contains the overall program flow, including initial * setup of all components and the main program loop. */ int main(void) { /// moodlight init init(); /// LUFA init SetupHardware(); RingBuffer_InitBuffer(&USBtoUSART_Buffer, USBtoUSART_Buffer_Data, sizeof(USBtoUSART_Buffer_Data)); RingBuffer_InitBuffer(&USARTtoUSB_Buffer, USARTtoUSB_Buffer_Data, sizeof(USARTtoUSB_Buffer_Data)); sei(); /// greetings to the user via USB //helloworld(); /// main loop for (;;) { mood(); /* Only try to read in bytes from the CDC interface if the transmit buffer is not full */ if (!(RingBuffer_IsFull(&USBtoUSART_Buffer))) { int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface); /* Read bytes from the USB OUT endpoint into the USART transmit buffer */ if (!(ReceivedByte < 0)) RingBuffer_Insert(&USBtoUSART_Buffer, ReceivedByte); } /* Check if the UART receive buffer flush timer has expired or the buffer is nearly full */ uint16_t BufferCount = RingBuffer_GetCount(&USARTtoUSB_Buffer); if ((TIFR0 & (1 << TOV0)) || (BufferCount > (uint8_t)(sizeof(USARTtoUSB_Buffer_Data) * .75))) { /* Clear flush timer expiry flag */ TIFR0 |= (1 << TOV0); /* Read bytes from the USART receive buffer into the USB IN endpoint */ while (BufferCount--) { /* Try to send the next byte of data to the host, abort if there is an error without dequeuing */ if (CDC_Device_SendByte(&VirtualSerial_CDC_Interface, RingBuffer_Peek(&USARTtoUSB_Buffer)) != ENDPOINT_READYWAIT_NoError) { break; } /* Dequeue the already sent byte from the buffer now we have confirmed that no transmission error occurred */ RingBuffer_Remove(&USARTtoUSB_Buffer); } } CDC_Device_USBTask(&VirtualSerial_CDC_Interface); USB_USBTask(); } }
qint32 cMediaInfo::writeFilename() { QSqlQuery query; query.prepare("SELECT id FROM file WHERE fileName=:fileName AND fileSize=:fileSize AND fileDate=:fileDate;"); query.bindValue(":fileName", fileName()); query.bindValue(":fileSize", fileSize()); query.bindValue(":fileDate", fileDate()); if(!query.exec()) { myDebug << query.lastError().text(); return(-1); } if(query.next()) query.prepare("UPDATE file SET fileType=:fileType, length=:length, bitrate=:bitrate, sampleRate=:sampleRate, channels=:channels, bitsPerSample=:bitsPerSample, layer=:layer, version=:version, sampleWidth=:sampleWidth, sampleFrames=:sampleFrames, isEncrypted=:isEncrypted, trackGain=:trackGain, albumGain=:albumGain, trackPeak=:trackPeak, albumPeak=:albumPeak, protectionEnabled=:protectionEnabled, channelMode=:channelMode, isCopyrighted=:isCopyrighted, isOriginal=:isOriginal, album=:album, title=:title, copyright=:copyright, trackNumber=:trackNumber, contentGroupDescription=:contentGroupDescription, subTitle=:subTitle, originalAlbum=:originalAlbum, partOfSet=:partOfSet, subTitleOfSet=:subTitleOfSet, internationalStandardRecordingCode=:internationalStandardRecordingCode, leadArtist=:leadArtist, band=:band, conductor=:conductor, interpret=:interpret, originalArtist=:originalArtist, textWriter=:textWriter, originalTextWriter=:originalTextWriter, composer=:composer, encodedBy=:encodedBy, beatsPerMinute=:beatsPerMinute, language=:language, contentType=:contentType, mediaType=:mediaType, mood=:mood, producedNotice=:producedNotice, publisher=:publisher, fileOwner=:fileOwner, internetRadioStationName=:internetRadioStationName, internetRadioStationOwner=:internetRadioStationOwner, originalFilename=:originalFilename, playlistDelay=:playlistDelay, encodingTime=:encodingTime, originalReleaseTime=:originalReleaseTime, recordingTime=:recordingTime, releaseTime=:releaseTime, taggingTime=:taggingTime, swhwSettings=:swhwSettings, albumSortOrder=:albumSortOrder, performerSortOrder=:performerSortOrder, titleSortOrder=:titleSortOrder, synchronizedLyrics=:synchronizedLyrics, unsynchronizedLyrics=:unsynchronizedLyrics WHERE filename=:filename AND filesize=:filesize AND filedate=:filedate;"); else query.prepare("INSERT INTO file (fileName, fileSize, fileDate, fileType, length, bitrate, sampleRate, channels, bitsPerSample, layer, version, sampleWidth, sampleFrames, isEncrypted, trackGain, albumGain, trackPeak, albumPeak, protectionEnabled, channelMode, isCopyrighted, isOriginal, album, title, copyright, trackNumber, contentGroupDescription, subTitle, originalAlbum, partOfSet, subTitleOfSet, internationalStandardRecordingCode, leadArtist, band, conductor, interpret, originalArtist, textWriter, originalTextWriter, composer, encodedBy, beatsPerMinute, language, contentType, mediaType, mood, producedNotice, publisher, fileOwner, internetRadioStationName, internetRadioStationOwner, originalFilename, playlistDelay, encodingTime, originalReleaseTime, recordingTime, releaseTime, taggingTime, swhwSettings, albumSortOrder, performerSortOrder, titleSortOrder, synchronizedLyrics, unsynchronizedLyrics) VALUES (:fileName, :fileSize, :fileDate, :fileType, :length, :bitrate, :sampleRate, :channels, :bitsPerSample, :layer, :version, :sampleWidth, :sampleFrames, :isEncrypted, :trackGain, :albumGain, :trackPeak, :albumPeak, :protectionEnabled, :channelMode, :isCopyrighted, :isOriginal, :album, :title, :copyright, :trackNumber, :contentGroupDescription, :subTitle, :originalAlbum, :partOfSet, :subTitleOfSet, :internationalStandardRecordingCode, :leadArtist, :band, :conductor, :interpret, :originalArtist, :textWriter, :originalTextWriter, :composer, :encodedBy, :beatsPerMinute, :language, :contentType, :mediaType, :mood, :producedNotice, :publisher, :fileOwner, :internetRadioStationName, :internetRadioStationOwner, :originalFilename, :playlistDelay, :encodingTime, :originalReleaseTime, :recordingTime, :releaseTime, :taggingTime, :swhwSettings, :albumSortOrder, :performerSortOrder, :titleSortOrder, :synchronizedLyrics, :unsynchronizedLyrics);"); query.bindValue(":fileName", fileName()); query.bindValue(":fileSize", fileSize()); query.bindValue(":fileDate", fileDate()); query.bindValue(":fileType", fileType()); query.bindValue(":length", length()); query.bindValue(":bitrate", bitrate()); query.bindValue(":sampleRate", sampleRate()); query.bindValue(":channels", channels()); query.bindValue(":bitsPerSample", bitsPerSample()); query.bindValue(":layer", layer()); query.bindValue(":version", version()); query.bindValue(":sampleWidth", sampleWidth()); query.bindValue(":sampleFrames", sampleFrames()); query.bindValue(":isEncrypted", isEncrypted()); query.bindValue(":trackGain", trackGain()); query.bindValue(":albumGain", albumGain()); query.bindValue(":trackPeak", trackPeak()); query.bindValue(":albumPeak", albumPeak()); query.bindValue(":protectionEnabled", protectionEnabled()); query.bindValue(":channelMode", channelMode()); query.bindValue(":isCopyrighted", isCopyrighted()); query.bindValue(":isOriginal", isOriginal()); query.bindValue(":album", album()); query.bindValue(":title", title()); query.bindValue(":copyright", copyright()); query.bindValue(":trackNumber", trackNumber()); query.bindValue(":contentGroupDescription", contentGroupDescription()); query.bindValue(":subTitle", subTitle()); query.bindValue(":originalAlbum", originalAlbum()); query.bindValue(":partOfSet", partOfSet()); query.bindValue(":subTitleOfSet", subTitleOfSet()); query.bindValue(":internationalStandardRecordingCode", internationalStandardRecordingCode()); query.bindValue(":leadArtist", leadArtist()); query.bindValue(":band", band()); query.bindValue(":conductor", conductor()); query.bindValue(":interpret", interpret().join(", ")); query.bindValue(":originalArtist", originalArtist()); query.bindValue(":textWriter", textWriter()); query.bindValue(":originalTextWriter", originalTextWriter()); query.bindValue(":composer", composer()); query.bindValue(":encodedBy", encodedBy()); query.bindValue(":beatsPerMinute", beatsPerMinute()); query.bindValue(":language", language().join(", ")); query.bindValue(":contentType", contentType().join(", ")); query.bindValue(":mediaType", mediaType().join(", ")); query.bindValue(":mood", mood()); query.bindValue(":producedNotice", producedNotice()); query.bindValue(":publisher", publisher()); query.bindValue(":fileOwner", fileOwner()); query.bindValue(":internetRadioStationName", internetRadioStationName()); query.bindValue(":internetRadioStationOwner", internetRadioStationOwner()); query.bindValue(":originalFilename", originalFilename()); query.bindValue(":playlistDelay", playlistDelay()); query.bindValue(":encodingTime", encodingTime()); query.bindValue(":originalReleaseTime", originalReleaseTime()); query.bindValue(":recordingTime", recordingTime()); query.bindValue(":releaseTime", releaseTime()); query.bindValue(":taggingTime", taggingTime()); query.bindValue(":swhwSettings", swhwSettings().join(", ")); query.bindValue(":albumSortOrder", albumSortOrder()); query.bindValue(":performerSortOrder", performerSortOrder()); query.bindValue(":titleSortOrder", titleSortOrder()); query.bindValue(":synchronizedLyrics", synchronizedLyrics().join()); query.bindValue(":unsynchronizedLyrics", unsynchronizedLyrics().join("||")); if(!query.exec()) { myDebug << query.lastError().text(); return(-1); } query.prepare("SELECT id FROM file WHERE fileName=:fileName AND fileSize=:fileSize AND fileDate=:fileDate;"); query.bindValue(":fileName", fileName()); query.bindValue(":fileSize", fileSize()); query.bindValue(":fileDate", fileDate()); if(!query.exec()) { myDebug << query.lastError().text(); return(-1); } if(query.next()) return(query.value("id").toInt()); return(-1); }