Author Topic: Getting started writing a plugin  (Read 5749 times)

beclawat

  • New User

  • Offline
  • *
  • 10
Getting started writing a plugin
« on: August 26, 2015, 04:04:15 AM »
I am looking to write a plugin that will fill the playlist as close as possible to exactly fit either a time or an event. First, my main problem is how to get a plugin to load. I am referencing PluginInterface.dll and System.Windows.Forms.dll. I have the Class and, Class file and Namespace all with the same name. Is there anything else I need to do to get the plugin to load.

AndyDeGroo

  • Guest
Re: Getting started writing a plugin
« Reply #1 on: August 26, 2015, 04:17:27 AM »
Hi,

First, your main plugin class must implement IPlugin interface.

Some actual plugin source code was provided by SnowHow in this post. That may help.

Also, get ILSpy.

beclawat

  • New User

  • Offline
  • *
  • 10
Re: Getting started writing a plugin
« Reply #2 on: August 26, 2015, 04:35:23 AM »
I am of course implementing IPlugin. DOH Should have mentioned that in the first place.

AndyDeGroo

  • Guest
Re: Getting started writing a plugin
« Reply #3 on: August 26, 2015, 05:04:00 AM »
One thing that may not be obvious - assembly has to target .NET 2.0.
I know, it sucks if you want to use all the shiny new toys available in .NET 4.x but, hey, 2.0 assemblies can (in theory) run under Windows 98. :D

beclawat

  • New User

  • Offline
  • *
  • 10
Re: Getting started writing a plugin
« Reply #4 on: August 26, 2015, 05:14:12 AM »
I had to target 3.5 as PluginInterface.dll references an assembly that only comes with 3.5. That got it to load.

AndyDeGroo

  • Guest
Re: Getting started writing a plugin
« Reply #5 on: August 26, 2015, 05:30:40 AM »
Ah, yes. .NET 3.5 it is. Sorry for misleading.

beclawat

  • New User

  • Offline
  • *
  • 10
Re: Getting started writing a plugin
« Reply #6 on: August 26, 2015, 05:34:57 AM »
Well I have code firing on song/track change which is a good start. Now to figure out how best to do what I want to do. I am sure there are lots of people on these forums that have ideas on how to fill out to a time. I should probably figure out actions and be event driven rather than trying to sort out filling time on track change (I should be able to figure that out for now). Thank you for getting my plugin loading and firing however.

AndyDeGroo

  • Guest
Re: Getting started writing a plugin
« Reply #7 on: August 26, 2015, 10:13:16 AM »
Well, there are not many on here who could help with plugin development. AFAIK, Marius, SnowHow and myself.

I'm not sure if hooking on track change will work, because TrackChanged() is called after current track starts to play and after playlist has changed, which may result in new tracks added to playlist before you can react. You should also note that this method is called from a separate thread.
Instead, your plugin could use PlaylistChanged(). Despite its name the it is called before playlist is changed. Your plugin could modify the playlist even before Plugin_Playlist reflects changes in UI if your plugin is loaded before Plugin_Playlist, which is determined by *.dll file order in Plugins directory.

Since RadioDJ does not keep track of total playlist duration, your plugin will have to iterate over playlist items and sum durations to determine if tracks fit in the hour.
If the conditions are met, stop Auto DJ and do your magic.
That could slow down Auto DJ but I can't tell for sure without testing.

beclawat

  • New User

  • Offline
  • *
  • 10
Re: Getting started writing a plugin
« Reply #8 on: August 27, 2015, 05:08:14 AM »
What I meant by there being lots of users with ideas was that there will be lots of people with ideas as to if I should try to clip a few seconds of up coming tracks to fit an extra in or insert jingles and idents or an instrumental loop or a mix of those previously mentioned. I will have a look at PlayListChanged as well.

Does PlayListChanged fire each time a new track is added or removed from the playlist? That is what I seem to be noticing in my testing. If that is the case then my job requires a little bit less complexity as I don't have to loop over the playlist to calculate the total time.

AndyDeGroo

  • Guest
Re: Getting started writing a plugin
« Reply #9 on: August 27, 2015, 08:03:19 AM »
IMO, you should focus on basic functionality first and test the best approach. More features, like choosing between clipping music/adding jingles/whatnot, can be added later.
Creating a poll would be a good way to understand what folks want and which direction to go.

beclawat

  • New User

  • Offline
  • *
  • 10
Re: Getting started writing a plugin
« Reply #10 on: August 27, 2015, 08:09:27 AM »
I am trying to figure out how best to implement basic functionality first :). So does PlayList changed fire when any change is made to the playlist?

Marius

  • Administrator
  • Hero Member

  • Offline
  • *****
  • 5688
    • Radio DJ
Re: Getting started writing a plugin
« Reply #11 on: August 27, 2015, 08:31:50 AM »
Yes, whenever a file is inserted/deleted from the playlist, it is called PlaylistChanged().
DOWNLOADS PAGE

HOW TO FIX RADIODJ DATABASE
----------------
Please don't PM me for support requests. Use the forums instead.

beclawat

  • New User

  • Offline
  • *
  • 10
Re: Getting started writing a plugin
« Reply #12 on: August 31, 2015, 08:10:22 AM »
I am looking at using Event Actions as I can see doing it automatically every hour is not what I want and probably what many don't want. I have the following code set up:
double mainPlayListLength = 0;
List<rdjInterface.Events.EventAction> myEvents = new List<Events.EventAction>();
bool IPlugin.HasActions
        {
            get
            {
                return true;
            }
        }
List<Events.EventAction> IPlugin.AvailableActions()
        {
            return myEvents;
        }
void IPlugin.Initialize(IHost Host)
        {
            host = Host;

            myEvents.Add(new Events.EventAction("TimeFiller", "FillTime", PluginActionTypes.Other, "Fit playlist to the hour."));
        }
        bool IPlugin.RunAction(string ActionName, string[] args)
        {

            DateTime newsStart = DateTime.Parse(DateTime.Now.AddHours(1).Hour + ":00:24");

            if (ActionName.Equals("FillTime"))
            {
                String output = "";
                MessageBox.Show("Test");
                foreach (TrackPlayer tp in host.MainPlaylist)
                {
                   
                    mainPlayListLength += tp.TrackData.Duration;
                    output += "Title: " + tp.TrackData.Title + Environment.NewLine + "Duration: " + tp.TrackData.Duration + Environment.NewLine + "TotalPlayListTime: " + mainPlayListLength + Environment.NewLine + "Time playlist will end: " + DateTime.Now.AddSeconds(mainPlayListLength).ToShortTimeString() + Environment.NewLine;
                    System.IO.File.AppendAllText(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\RDJPlugin.log", output);
                    MessageBox.Show(output);
                }
                MessageBox.Show(mainPlayListLength.ToString());
            }
           
            return true;
        }

If I set up an event, I can add the action FillTime to the event, however none of the MessageBoxes appear nor does the output file I expect.

Anny advice is appreciated.

Marius

  • Administrator
  • Hero Member

  • Offline
  • *****
  • 5688
    • Radio DJ
Re: Getting started writing a plugin
« Reply #13 on: August 31, 2015, 09:33:36 AM »
When you are adding the new event action, you need to make sure that the plugin name is correct, otherwise the plugin won't be found when the action is called.

You can use reflection to avoid this problem:
Code: [Select]
myEvents.Add(new Events.EventAction(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name(), "FillTime", PluginActionTypes.Other, "Fit playlist to the hour."));
DOWNLOADS PAGE

HOW TO FIX RADIODJ DATABASE
----------------
Please don't PM me for support requests. Use the forums instead.

Major Armstrong

  • Jr. Member

  • Offline
  • **
  • 63
    • Armstrong Memorial Site
Re: Getting started writing a plugin
« Reply #14 on: November 20, 2015, 11:24:10 AM »
This would be an excellent plug-in!  Best of luck in your work.
 :cool:
Major Edwin H. Armstrong
(1890 - 1954)
Inventor of FM Radio